diff options
20 files changed, 2464 insertions, 3103 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index a5ce3fa4a..2c2d90dc4 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - (C) 2010,2011 Christian Grothoff (and other contributing authors) + This file is part of GNUnet. + (C) 2010,2011 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 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. + 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. -*/ + 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/gnunet-service-transport.c @@ -40,7 +40,6 @@ #include "gnunet-service-transport_manipulation.h" #include "transport.h" - /** * Information we need for an asynchronous session kill. */ @@ -72,7 +71,6 @@ struct SessionKiller GNUNET_SCHEDULER_TaskIdentifier task; }; - /* globals */ /** @@ -130,7 +128,6 @@ static struct SessionKiller *sk_head; */ static struct SessionKiller *sk_tail; - /** * Transmit our HELLO message to the given (connected) neighbour. * @@ -144,24 +141,21 @@ static struct SessionKiller *sk_tail; */ static void transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { const struct GNUNET_MessageHeader *hello = cls; - if ( GNUNET_NO == GST_neighbours_test_connected(target) ) + if (GNUNET_NO == GST_neighbours_test_connected (target)) return; - GST_neighbours_send (target, - hello, - ntohs (hello->size), - hello_expiration, NULL, NULL); + GST_neighbours_send (target, hello, ntohs (hello->size), hello_expiration, + NULL, NULL ); } - /** * My HELLO has changed. Tell everyone who should know. * @@ -169,14 +163,12 @@ transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, * @param hello new HELLO */ static void -process_hello_update (void *cls, - const struct GNUNET_MessageHeader *hello) +process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) { GST_clients_broadcast (hello, GNUNET_NO); GST_neighbours_iterate (&transmit_our_hello, (void *) hello); } - /** * We received some payload. Prepare to pass it on to our clients. * @@ -188,30 +180,26 @@ process_hello_update (void *cls, */ static struct GNUNET_TIME_Relative process_payload (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_HELLO_Address *address, struct Session *session, + const struct GNUNET_MessageHeader *message) { struct GNUNET_TIME_Relative ret; int do_forward; struct InboundMessage *im; size_t msg_size = ntohs (message->size); - size_t size = - sizeof (struct InboundMessage) + msg_size; + size_t size = sizeof(struct InboundMessage) + msg_size; char buf[size] GNUNET_ALIGN; do_forward = GNUNET_SYSERR; ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); - if (! GST_neighbours_test_connected (peer)) + if (!GST_neighbours_test_connected (peer)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Discarded %u bytes type %u payload from peer `%s'\n", - msg_size, - ntohs (message->type), GNUNET_i2s (peer)); - GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# bytes payload discarded due to not connected peer"), - msg_size, GNUNET_NO); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Discarded %u bytes type %u payload from peer `%s'\n", msg_size, + ntohs (message->type), GNUNET_i2s (peer)); + GNUNET_STATISTICS_update (GST_stats, gettext_noop + ("# bytes payload discarded due to not connected peer"), msg_size, + GNUNET_NO); return ret; } @@ -228,7 +216,6 @@ process_payload (const struct GNUNET_PeerIdentity *peer, return ret; } - /** * Task to asynchronously terminate a session. * @@ -236,19 +223,16 @@ process_payload (const struct GNUNET_PeerIdentity *peer, * @param tc scheduler context */ static void -kill_session_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct SessionKiller *sk = cls; sk->task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); - sk->plugin->disconnect_session (sk->plugin->cls, - sk->session); - GNUNET_free (sk); + GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); + sk->plugin->disconnect_session (sk->plugin->cls, sk->session); + GNUNET_free(sk); } - /** * Force plugin to terminate session due to communication * issue. @@ -257,8 +241,7 @@ kill_session_task (void *cls, * @param session session to termiante */ static void -kill_session (const char *plugin_name, - struct Session *session) +kill_session (const char *plugin_name, struct Session *session) { struct GNUNET_TRANSPORT_PluginFunctions *plugin; struct SessionKiller *sk; @@ -269,19 +252,17 @@ kill_session (const char *plugin_name, plugin = GST_plugins_find (plugin_name); if (NULL == plugin) { - GNUNET_break (0); + GNUNET_break(0); return; } /* need to issue disconnect asynchronously */ sk = GNUNET_new (struct SessionKiller); sk->session = session; sk->plugin = plugin; - sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, - sk); - GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk); + sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk); + GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); } - /** * Function called by the transport for each received message. * @@ -303,35 +284,25 @@ kill_session (const char *plugin_name, */ struct GNUNET_TIME_Relative GST_receive_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, + const struct GNUNET_HELLO_Address *address, struct Session *session, - const char *sender_address, - uint16_t sender_address_len) + const struct GNUNET_MessageHeader *message) { const char *plugin_name = cls; struct GNUNET_TIME_Relative ret; - struct GNUNET_HELLO_Address address; uint16_t type; - address.peer = *peer; - address.address = sender_address; - address.address_length = sender_address_len; - address.transport_name = plugin_name; ret = GNUNET_TIME_UNIT_ZERO; if (NULL == message) goto end; type = ntohs (message->type); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received Message with type %u from peer `%s'\n", - type, - GNUNET_i2s (peer)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received Message with type %u from peer `%s'\n", type, + GNUNET_i2s (&address->peer)); - GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# bytes total received"), - ntohs (message->size), GNUNET_NO); - GST_neighbours_notify_data_recv (peer, &address, session, message); + GNUNET_STATISTICS_update (GST_stats, gettext_noop + ("# bytes total received"), ntohs (message->size), GNUNET_NO); + GST_neighbours_notify_data_recv (&address->peer, address, session, message); switch (type) { @@ -339,85 +310,76 @@ GST_receive_callback (void *cls, /* Legacy HELLO message, discard */ return ret; case GNUNET_MESSAGE_TYPE_HELLO: - if (GNUNET_OK != - GST_validation_handle_hello (message)) + if (GNUNET_OK != GST_validation_handle_hello (message)) { - GNUNET_break_op (0); + GNUNET_break_op(0); kill_session (plugin_name, session); } return ret; case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing `%s' from `%s'\n", "PING", - (sender_address != - NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); - if (GNUNET_OK != - GST_validation_handle_ping (peer, message, &address, session)) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", "PING", GST_plugins_a2s (address)); + if (GNUNET_OK + != GST_validation_handle_ping (&address->peer, message, address, session)) kill_session (plugin_name, session); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing `%s' from `%s'\n", "PONG", - (sender_address != - NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); - if (GNUNET_OK != - GST_validation_handle_pong (peer, message)) + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", "PONG", + GST_plugins_a2s (address)); + if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) { - GNUNET_break_op (0); + GNUNET_break_op(0); kill_session (plugin_name, session); } break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: - if (GNUNET_OK != - GST_neighbours_handle_connect (message, peer, &address, session)) + if (GNUNET_OK + != GST_neighbours_handle_connect (message, &address->peer, address, session)) { - GNUNET_break_op (0); + GNUNET_break_op(0); kill_session (plugin_name, session); } break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: - if (GNUNET_OK != - GST_neighbours_handle_connect_ack (message, peer, &address, session)) + if (GNUNET_OK + != GST_neighbours_handle_connect_ack (message, &address->peer, address, session)) { kill_session (plugin_name, session); } break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: - if (GNUNET_OK != - GST_neighbours_handle_session_ack (message, peer, &address, session)) + if (GNUNET_OK + != GST_neighbours_handle_session_ack (message, &address->peer, address, session)) { - GNUNET_break_op (0); + GNUNET_break_op(0); kill_session (plugin_name, session); } break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: - GST_neighbours_handle_disconnect_message (peer, message); + GST_neighbours_handle_disconnect_message (&address->peer, message); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: - GST_neighbours_keepalive (peer, message); + GST_neighbours_keepalive (&address->peer, message); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: - GST_neighbours_keepalive_response (peer, message); + GST_neighbours_keepalive_response (&address->peer, message); break; default: /* should be payload */ - GNUNET_STATISTICS_update (GST_stats, - gettext_noop - ("# bytes payload received"), - ntohs (message->size), GNUNET_NO); - GST_neighbours_notify_payload_recv (peer, &address, session, message); - ret = process_payload (peer, &address, session, message); + GNUNET_STATISTICS_update (GST_stats, gettext_noop + ("# bytes payload received"), ntohs (message->size), GNUNET_NO); + GST_neighbours_notify_payload_recv (&address->peer, address, session, message); + ret = process_payload (&address->peer, address, session, message); break; } -end: - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Allowing receive from peer %s to continue in %s\n", - GNUNET_i2s (peer), - GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); + end: + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Allowing receive from peer %s to continue in %s\n", GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); return ret; } - /** * Function that will be called for each address the transport * is aware that it might be reachable under. Update our HELLO. @@ -425,26 +387,15 @@ end: * @param cls name of the plugin (const char*) * @param add_remove should the address added (YES) or removed (NO) from the * set of valid addresses? - * @param addr one of the addresses of the host - * the specific address format depends on the transport - * @param addrlen length of the @a addr - * @param dest_plugin destination plugin to use this address with + * @param address the address to add or remove */ static void plugin_env_address_change_notification (void *cls, int add_remove, - const void *addr, size_t addrlen, - const char *dest_plugin) + const struct GNUNET_HELLO_Address *address) { - struct GNUNET_HELLO_Address address; - - address.peer = GST_my_identity; - address.transport_name = dest_plugin; - address.address = addr; - address.address_length = addrlen; - GST_hello_modify_addresses (add_remove, &address); + GST_hello_modify_addresses (add_remove, address); } - /** * Function that will be called whenever the plugin internally * cleans up a session pointer and hence the service needs to @@ -460,22 +411,21 @@ plugin_env_address_change_notification (void *cls, int add_remove, */ static void plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, - struct Session *session) + struct Session *session) { const char *transport_name = cls; struct GNUNET_HELLO_Address address; struct SessionKiller *sk; - GNUNET_assert (strlen (transport_name) > 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Session %p to peer `%s' ended \n", - session, - GNUNET_i2s (peer)); + GNUNET_assert(strlen (transport_name) > 0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' ended \n", + session, GNUNET_i2s (peer)); if (NULL != session) - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "transport-ats", - "Telling ATS to destroy session %p from peer %s\n", - session, GNUNET_i2s (peer)); + GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "transport-ats", "Telling ATS to destroy session %p from peer %s\n", + session, GNUNET_i2s (peer)); + + memset (&address, '\0', sizeof (address)); address.peer = *peer; address.address = NULL; address.address_length = 0; @@ -488,15 +438,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, { if (sk->session == session) { - GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); + GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); GNUNET_SCHEDULER_cancel (sk->task); - GNUNET_free (sk); + GNUNET_free(sk); break; } } } - /** * Function that will be called to figure if an address is an loopback, * LAN, WAN etc. address @@ -507,9 +456,8 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, * @return ATS Information containing the network type */ static struct GNUNET_ATS_Information -plugin_env_address_to_type (void *cls, - const struct sockaddr *addr, - size_t addrlen) +plugin_env_address_to_type (void *cls, const struct sockaddr *addr, + size_t addrlen) { struct GNUNET_ATS_Information ats; @@ -517,24 +465,23 @@ plugin_env_address_to_type (void *cls, ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); if (NULL == GST_ats) { - GNUNET_break (0); + GNUNET_break(0); return ats; } - if (((addr->sa_family != AF_INET) && (addrlen != sizeof (struct sockaddr_in))) && - ((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) && - (addr->sa_family != AF_UNIX)) + if (((addr->sa_family != AF_INET) && (addrlen != sizeof(struct sockaddr_in))) + && ((addr->sa_family != AF_INET6) + && (addrlen != sizeof(struct sockaddr_in6))) + && (addr->sa_family != AF_UNIX)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Malformed address with length %u `%s'\n", - addrlen, - GNUNET_a2s (addr, addrlen)); - GNUNET_break (0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Malformed address with length %u `%s'\n", addrlen, + GNUNET_a2s (addr, addrlen)); + GNUNET_break(0); return ats; } return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen); } - /** * Notify ATS about the new address including the network this address is * located in. @@ -546,9 +493,8 @@ plugin_env_address_to_type (void *cls, */ void GST_ats_add_address (const struct GNUNET_HELLO_Address *address, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + struct Session *session, const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { struct GNUNET_TRANSPORT_PluginFunctions *papi; struct GNUNET_ATS_Information ats2[ats_count + 1]; @@ -557,48 +503,43 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, /* valid new address, let ATS know! */ if (NULL == address->transport_name) { - GNUNET_break (0); + GNUNET_break(0); return; } if (NULL == (papi = GST_plugins_find (address->transport_name))) { /* we don't have the plugin for this address */ - GNUNET_break (0); + GNUNET_break(0); return; } if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS already knows the address, not passing it on again\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "ATS already knows the address, not passing it on again\n"); return; } net = papi->get_network (NULL, session); if (GNUNET_ATS_NET_UNSPECIFIED == net) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not obtain a valid network for `%s' %s (%s)\n"), - GNUNET_i2s (&address->peer), - GST_plugins_a2s (address), - address->transport_name); - GNUNET_break (0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Could not obtain a valid network for `%s' %s (%s)\n"), + GNUNET_i2s (&address->peer), GST_plugins_a2s (address), + address->transport_name); + GNUNET_break(0); } ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - ats2[0].value = htonl(net); - memcpy (&ats2[1], ats, sizeof (struct GNUNET_ATS_Information) * ats_count); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", - GNUNET_i2s (&address->peer), - (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), - session, - GNUNET_ATS_print_network_type(net)); - GNUNET_ATS_address_add (GST_ats, - address, session, - ats2, ats_count + 1); + ats2[0].value = htonl (net); + memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", + GNUNET_i2s (&address->peer), + (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), + session, GNUNET_ATS_print_network_type (net)); + GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1); } - /** * Notify ATS about property changes to an address * @@ -610,10 +551,8 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, */ void GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_HELLO_Address *address, struct Session *session, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct GNUNET_ATS_Information *ats_new; @@ -622,26 +561,23 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, /* Call to manipulation to manipulate ATS information */ ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats, - ats_count); + ats_count); if (NULL == ats_new) { GNUNET_break(0); return; } - if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, - address, session, ats_new, ats_count)) + if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, address, session, + ats_new, ats_count)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), - GNUNET_i2s (peer), - address->transport_name, - GST_plugins_a2s (address), - session); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), + GNUNET_i2s (peer), address->transport_name, GST_plugins_a2s (address), + session); } - GNUNET_free (ats_new); + GNUNET_free(ats_new); } - /** * Function that will be called to figure if an address is an loopback, * LAN, WAN etc. address @@ -656,63 +592,37 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, */ static void plugin_env_update_metrics (void *cls, - const struct GNUNET_PeerIdentity *peer, - const void *address, - uint16_t address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { - const char *plugin_name = cls; - struct GNUNET_HELLO_Address haddress; - if ((NULL == ats) || (0 == ats_count)) return; - GNUNET_assert (NULL != GST_ats); - - haddress.peer = *peer; - haddress.address = address; - haddress.address_length = address_len; - haddress.transport_name = plugin_name; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Updating metrics for peer `%s' address %s session %p\n", - GNUNET_i2s (peer), - GST_plugins_a2s (&haddress), - session); - GST_ats_update_metrics (peer, &haddress, session, ats, ats_count); -} + GNUNET_assert(NULL != GST_ats); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Updating metrics for peer `%s' address %s session %p\n", + GNUNET_i2s (&address->peer), GST_plugins_a2s (address), session); + GST_ats_update_metrics (&address->peer, address, session, ats, ats_count); +} /** - * Plugin tells transport service about a new (inbound) session + * Plugin tells transport service about a new inbound session * * @param cls unused - * @param peer the peer - * @param plugin plugin name - * @param address address - * @param address_len @a address length + * @param address the address * @param session the new session * @param ats ats information * @param ats_count number of @a ats information */ static void -plugin_env_session_start (void *cls, - const struct GNUNET_PeerIdentity *peer, - const char *plugin, - const void *address, uint16_t address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) +plugin_env_session_start (void *cls, struct GNUNET_HELLO_Address *address, + struct Session *session, const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { - struct GNUNET_HELLO_Address *addr; - - if (NULL == peer) - { - GNUNET_break(0); - return; - } - if (NULL == plugin) + int inbound; + if (NULL == address) { GNUNET_break(0); return; @@ -723,17 +633,18 @@ plugin_env_session_start (void *cls, return; } - addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", - plugin, - session, - GNUNET_i2s (peer), - GST_plugins_a2s (addr)); - GST_ats_add_address (addr, session, ats, ats_count); - GNUNET_free(addr); -} + if (GNUNET_HELLO_ADDRESS_INFO_INBOUND + == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + inbound = GNUNET_YES; + else + inbound = GNUNET_NO; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n", + address->transport_name, (GNUNET_YES == inbound) ? "inbound" : "outbound", + session, GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); + GST_ats_add_address (address, session, ats, ats_count); +} /** * Function called by ATS to notify the callee that the @@ -753,14 +664,11 @@ plugin_env_session_start (void *cls, * @param ats_count number of @a ats elements */ static void -ats_request_address_change (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) +ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { uint32_t bw_in = ntohl (bandwidth_in.value__); uint32_t bw_out = ntohl (bandwidth_out.value__); @@ -768,19 +676,17 @@ ats_request_address_change (void *cls, /* ATS tells me to disconnect from peer */ if ((0 == bw_in) && (0 == bw_out)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS tells me to disconnect from peer `%s'\n", - GNUNET_i2s (&address->peer)); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "ATS tells me to disconnect from peer `%s'\n", + GNUNET_i2s (&address->peer)); GST_neighbours_force_disconnect (&address->peer); return; } GST_neighbours_switch_to_address (&address->peer, address, session, ats, - ats_count, bandwidth_in, - bandwidth_out); + ats_count, bandwidth_in, bandwidth_out); } - /** * Function called to notify transport users that another * peer connected to us. @@ -792,19 +698,19 @@ ats_request_address_change (void *cls, */ static void neighbours_connect_notification (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { - size_t len = sizeof (struct ConnectInfoMessage); + size_t len = sizeof(struct ConnectInfoMessage); char buf[len] GNUNET_ALIGN; struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; connections++; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "We are now connected to peer `%s' and %u peers in total\n", - GNUNET_i2s (peer), connections); - connect_msg->header.size = htons (sizeof (buf)); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "We are now connected to peer `%s' and %u peers in total\n", + GNUNET_i2s (peer), connections); + connect_msg->header.size = htons (sizeof(buf)); connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); connect_msg->id = *peer; connect_msg->quota_in = bandwidth_in; @@ -812,7 +718,6 @@ neighbours_connect_notification (void *cls, GST_clients_broadcast (&connect_msg->header, GNUNET_NO); } - /** * Function called to notify transport users that another * peer disconnected from us. @@ -822,24 +727,23 @@ neighbours_connect_notification (void *cls, */ static void neighbours_disconnect_notification (void *cls, - const struct GNUNET_PeerIdentity *peer) + const struct GNUNET_PeerIdentity *peer) { struct DisconnectInfoMessage disconnect_msg; connections--; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Peer `%s' disconnected and we are connected to %u peers\n", - GNUNET_i2s (peer), connections); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Peer `%s' disconnected and we are connected to %u peers\n", + GNUNET_i2s (peer), connections); GST_manipulation_peer_disconnect (peer); - disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage)); + disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage)); disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); disconnect_msg.reserved = htonl (0); disconnect_msg.peer = *peer; GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); } - /** * Function called to notify transport users that a neighbour peer changed its * active address. @@ -854,24 +758,23 @@ neighbours_disconnect_notification (void *cls, */ static void neighbours_changed_notification (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", GNUNET_i2s (peer), (NULL != address) ? GST_plugins_a2s (address) : "<none>", - GNUNET_TRANSPORT_p2s(state), - GNUNET_STRINGS_absolute_time_to_string(state_timeout)); + GNUNET_TRANSPORT_p2s (state), + GNUNET_STRINGS_absolute_time_to_string (state_timeout)); GST_clients_broadcast_peer_notification (peer, address, state, state_timeout); } - /** * Function called when the service shuts down. Unloads our plugins * and cancels pending validations. @@ -905,13 +808,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } if (NULL != GST_my_private_key) { - GNUNET_free (GST_my_private_key); + GNUNET_free(GST_my_private_key); GST_my_private_key = NULL; } GST_server = NULL; } - /** * Initiate transport service. * @@ -921,7 +823,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, - const struct GNUNET_CONFIGURATION_Handle *c) + const struct GNUNET_CONFIGURATION_Handle *c) { char *keyfile; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; @@ -932,42 +834,42 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, /* setup globals */ GST_cfg = c; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", - &keyfile)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", + &keyfile)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Transport service is lacking key configuration settings. Exiting.\n")); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Transport service is lacking key configuration settings. Exiting.\n")); GNUNET_SCHEDULER_shutdown (); return; } - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", - &hello_expiration)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_time (c, "transport", + "HELLO_EXPIRATION", &hello_expiration)) { hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; } GST_server = server; pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); - GNUNET_free (keyfile); - GNUNET_assert (NULL != pk); + GNUNET_free(keyfile); + GNUNET_assert(NULL != pk); GST_my_private_key = pk; GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, - &GST_my_identity.public_key); - GNUNET_assert (NULL != GST_my_private_key); + &GST_my_identity.public_key); + GNUNET_assert(NULL != GST_my_private_key); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "My identity is `%4s'\n", GNUNET_i2s (&GST_my_identity)); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "My identity is `%4s'\n", + GNUNET_i2s (&GST_my_identity)); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, - NULL); + NULL ); if (NULL == GST_peerinfo) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not access PEERINFO service. Exiting.\n")); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Could not access PEERINFO service. Exiting.\n")); GNUNET_SCHEDULER_shutdown (); return; } @@ -980,51 +882,50 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, { max_fd_rlimit = r_file.rlim_cur; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Maximum number of open files was: %u/%u\n", - r_file.rlim_cur, - r_file.rlim_max); + "Maximum number of open files was: %u/%u\n", + r_file.rlim_cur, + r_file.rlim_max); } max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ #endif - GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", &max_fd_cfg); + GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", + &max_fd_cfg); if (max_fd_cfg > max_fd_rlimit) - max_fd = max_fd_cfg; + max_fd = max_fd_cfg; else - max_fd = max_fd_rlimit; + max_fd = max_fd_rlimit; if (max_fd < DEFAULT_MAX_FDS) - max_fd = DEFAULT_MAX_FDS; + max_fd = DEFAULT_MAX_FDS; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Limiting number of sockets to %u: validation %u, neighbors: %u\n", - max_fd, (max_fd / 3) , (max_fd / 3) * 2); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Limiting number of sockets to %u: validation %u, neighbors: %u\n", + max_fd, (max_fd / 3), (max_fd / 3) * 2); - friend_only = GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology","FRIENDS-ONLY"); + friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", + "FRIENDS-ONLY"); if (GNUNET_SYSERR == friend_only) - friend_only = GNUNET_NO; /* According to topology defaults */ + friend_only = GNUNET_NO; /* According to topology defaults */ /* start subsystems */ - GST_hello_start (friend_only, &process_hello_update, NULL); - GNUNET_assert (NULL != GST_hello_get()); + GST_hello_start (friend_only, &process_hello_update, NULL ); + GNUNET_assert(NULL != GST_hello_get()); GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); - GST_ats = - GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); + GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, + NULL ); GST_manipulation_init (GST_cfg); GST_plugins_load (&GST_manipulation_recv, - &plugin_env_address_change_notification, - &plugin_env_session_start, - &plugin_env_session_end, - &plugin_env_address_to_type, - &plugin_env_update_metrics); - GST_neighbours_start (NULL, - &neighbours_connect_notification, - &neighbours_disconnect_notification, - &neighbours_changed_notification, - (max_fd / 3) * 2); + &plugin_env_address_change_notification, + &plugin_env_session_start, + &plugin_env_session_end, + &plugin_env_address_to_type, + &plugin_env_update_metrics); + GST_neighbours_start (NULL, &neighbours_connect_notification, + &neighbours_disconnect_notification, &neighbours_changed_notification, + (max_fd / 3) * 2); GST_clients_start (GST_server); GST_validation_start ((max_fd / 3)); } - /** * The main function for the transport service. * @@ -1033,11 +934,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main (int argc, char * const *argv) { - return (GNUNET_OK == - GNUNET_SERVICE_run (argc, argv, "transport", - GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; + return + (GNUNET_OK + == GNUNET_SERVICE_run (argc, argv, "transport", + GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1; } /* end of file gnunet-service-transport.c */ diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 75b387381..34ed61f9e 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h @@ -72,12 +72,12 @@ extern struct GNUNET_ATS_SchedulingHandle *GST_ats; */ typedef void (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - enum GNUNET_TRANSPORT_PeerState state, - struct GNUNET_TIME_Absolute state_timeout, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + enum GNUNET_TRANSPORT_PeerState state, + struct GNUNET_TIME_Absolute state_timeout, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); /** @@ -103,11 +103,9 @@ typedef void */ struct GNUNET_TIME_Relative GST_receive_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct Session *session, - const char *sender_address, - uint16_t sender_address_len); + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_MessageHeader *message); /** diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 1fbd56c24..ca7a40539 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -885,8 +885,10 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer msg->peer = *peer; msg->addrlen = htonl (alen); msg->pluginlen = htonl (tlen); + if (NULL != address) { + msg->local_address_info = htonl((uint32_t) address->local_info); addr = (char *) &msg[1]; memcpy (addr, address->address, alen); memcpy (&addr[alen], address->transport_name, tlen); diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 4521047c9..06171d306 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c @@ -529,9 +529,10 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_PeerIdentity *peer, * @return manipulated delay for next receive */ struct GNUNET_TIME_Relative -GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, struct Session *session, - const char *sender_address, uint16_t sender_address_len) +GST_manipulation_recv (void *cls, + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_MessageHeader *message) { struct TM_Peer *tmp; uint32_t p_recv_delay; @@ -547,7 +548,7 @@ GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, else m_delay = GNUNET_TIME_UNIT_ZERO; - if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer))) + if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, &address->peer))) { /* Manipulate receive delay */ p_recv_delay = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_RECEIVE); @@ -555,14 +556,15 @@ GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, m_delay.rel_value_us = p_recv_delay; /* Peer specific delay */ } - quota_delay = GST_receive_callback(cls, peer, message, session, - sender_address, sender_address_len); + quota_delay = GST_receive_callback(cls, address, session, message); if (quota_delay.rel_value_us > m_delay.rel_value_us) m_delay = quota_delay; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delaying next receive for peer `%s' for %s\n", GNUNET_i2s (peer), GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); + "Delaying next receive for peer `%s' for %s\n", + GNUNET_i2s (&address->peer), + GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); return m_delay; } diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h index 4fe68ade1..3b6beb8b7 100644 --- a/src/transport/gnunet-service-transport_manipulation.h +++ b/src/transport/gnunet-service-transport_manipulation.h @@ -79,11 +79,9 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, */ struct GNUNET_TIME_Relative GST_manipulation_recv (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct Session *session, - const char *sender_address, - uint16_t sender_address_len); + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_MessageHeader *message); /** * Function that will be called to manipulate ATS information according to diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index a386d7de0..af59b5fec 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -2300,11 +2300,11 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, return; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS tells us to switch to address '%s/%s' session %p for " + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "ATS tells us to switch to %s address '%s' session %p for " "peer `%s' in state %s/%d (quota in/out %u %u )\n", - (address->address_length != 0) ? GST_plugins_a2s (address): "<inbound>", - address->transport_name, + (GNUNET_HELLO_ADDRESS_INFO_INBOUND == (GNUNET_HELLO_ADDRESS_INFO_INBOUND & address->local_info)) ? "inbound" : "", + GST_plugins_a2s (address), session, GNUNET_i2s (peer), GNUNET_TRANSPORT_p2s (n->state), diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index c86bf67ff..80953e5ea 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -986,6 +986,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, addrend++; slen = strlen (addr) + 1; alen -= slen; + address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; address.address = addrend; address.address_length = alen; address.transport_name = addr; @@ -1298,6 +1299,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, address.address = addr; address.address_length = addrlen; address.transport_name = tname; + address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; ve = find_validation_entry (NULL, &address); if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) { diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c index a7d3cf3f5..f301d55b3 100644 --- a/src/transport/plugin_transport_bluetooth.c +++ b/src/transport/plugin_transport_bluetooth.c @@ -355,7 +355,9 @@ struct MacEndpoint /** * peer mac address */ - struct WlanAddress addr; + //struct WlanAddress addr; + + struct GNUNET_HELLO_Address *address; /** * Message delay for fragmentation context @@ -605,8 +607,8 @@ send_ack (void *cls, uint32_t msg_id, get_radiotap_header (endpoint, radio_header, size); get_wlan_header (endpoint->plugin, &radio_header->frame, - &endpoint->addr.mac, - size); + endpoint->address->address, + endpoint->address->address_length); memcpy (&radio_header[1], hdr, msize); if (NULL != GNUNET_HELPER_send (endpoint->plugin->suid_helper, @@ -742,7 +744,7 @@ create_session (struct MacEndpoint *endpoint, LOG (GNUNET_ERROR_TYPE_DEBUG, "Created new session for peer `%s' with endpoint %s\n", GNUNET_i2s (peer), - mac_to_string (&endpoint->addr.mac)); + mac_to_string (endpoint->address->address)); return session; } @@ -793,8 +795,8 @@ transmit_fragment (void *cls, get_radiotap_header (endpoint, radio_header, size); get_wlan_header (endpoint->plugin, &radio_header->frame, - &endpoint->addr.mac, - size); + endpoint->address->address, + endpoint->address->address_length); memcpy (&radio_header[1], hdr, msize); GNUNET_assert (NULL == fm->sh); fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, @@ -999,10 +1001,11 @@ create_macendpoint (struct Plugin *plugin, struct MacEndpoint *pos; for (pos = plugin->mac_head; NULL != pos; pos = pos->next) - if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress))) + if (0 == memcmp (addr, &pos->address->address, sizeof (struct WlanAddress))) return pos; pos = GNUNET_new (struct MacEndpoint); - pos->addr = *addr; + pos->address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, addr, + sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); pos->plugin = plugin; pos->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, @@ -1244,23 +1247,20 @@ 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 (struct WlanAddress))); + bluetooth_plugin_address_to_string (NULL, mas->endpoint->address, + mas->endpoint->address->address_length)); GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO messages received via Bluetooth"), 1, GNUNET_NO); plugin->env->receive (plugin->env->cls, - &tmpsource, - hdr, - mas->session, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); + mas->endpoint->address, + mas->session, + hdr); plugin->env->update_address_metrics (plugin->env->cls, - &tmpsource, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress), - mas->session, - &ats, 1); + mas->endpoint->address, + mas->session, + &ats, 1); break; case GNUNET_MESSAGE_TYPE_FRAGMENT: if (NULL == mas->endpoint) @@ -1271,7 +1271,8 @@ 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 (struct WlanAddress))); + bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); GNUNET_STATISTICS_update (plugin->env->stats, _("# fragments received via Bluetooth"), 1, GNUNET_NO); (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, @@ -1292,7 +1293,8 @@ 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 (struct WlanAddress)), + bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length), fm); mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); if (NULL != fm->cont) @@ -1307,13 +1309,15 @@ 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 (struct WlanAddress))); + bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); 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 (struct WlanAddress))); + bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); break; case GNUNET_MESSAGE_TYPE_WLAN_DATA: if (NULL == mas->endpoint) @@ -1373,17 +1377,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) (unsigned int) ntohs (hdr->type), GNUNET_i2s (&mas->session->target)); plugin->env->receive (plugin->env->cls, - &mas->session->target, - hdr, + mas->endpoint->address, mas->session, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); + hdr); plugin->env->update_address_metrics (plugin->env->cls, - &mas->session->target, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), - mas->session, - &ats, 1); + mas->endpoint->address, + mas->session, + &ats, 1); break; } return GNUNET_OK; @@ -1402,6 +1402,7 @@ handle_helper_message (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; struct WlanAddress wa; @@ -1428,24 +1429,26 @@ handle_helper_message (void *cls, void *client, memset (&wa, 0, sizeof (struct WlanAddress)); wa.mac = plugin->mac_address; wa.options = htonl(plugin->options); - plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - &wa, - sizeof (wa), - "bluetooth"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); + GNUNET_HELLO_address_free (address); } plugin->mac_address = cm->mac; plugin->have_mac = GNUNET_YES; memset (&wa, 0, sizeof (struct WlanAddress)); wa.mac = plugin->mac_address; wa.options = htonl(plugin->options); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received BT_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", mac_to_string (&cm->mac), GNUNET_i2s (plugin->env->my_identity)); - plugin->env->notify_address (plugin->env->cls, GNUNET_YES, - &wa, - sizeof (struct WlanAddress), - "bluetooth"); + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); + GNUNET_HELLO_address_free (address); + break; case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1682,7 +1685,8 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type, void * libgnunet_plugin_transport_bluetooth_done (void *cls) { - struct WlanAddress wa; + struct WlanAddress wa; + struct GNUNET_HELLO_Address *address; struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; struct MacEndpoint *endpoint; @@ -1696,14 +1700,17 @@ libgnunet_plugin_transport_bluetooth_done (void *cls) if (GNUNET_YES == plugin->have_mac) { - memset (&wa, 0, sizeof (wa)); - wa.options = htonl (plugin->options); - wa.mac = plugin->mac_address; - plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - &wa, - sizeof (struct WlanAddress), - "bluetooth"); - plugin->have_mac = GNUNET_NO; + memset (&wa, 0, sizeof(wa)); + wa.options = htonl (plugin->options); + wa.mac = plugin->mac_address; + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (struct WlanAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); + plugin->have_mac = GNUNET_NO; + + GNUNET_HELLO_address_free (address); } if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index ba7fd45a3..bd4487614 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -155,12 +155,7 @@ struct Session /** * Address */ - struct HttpAddress *addr; - - /** - * Address length - */ - size_t addrlen; + struct GNUNET_HELLO_Address *address; /** * ATS network type in NBO @@ -587,7 +582,7 @@ client_delete_session (struct Session *s) GNUNET_SERVER_mst_destroy (s->msg_tk); s->msg_tk = NULL; } - GNUNET_free (s->addr); + GNUNET_HELLO_address_free (s->address); GNUNET_free (s->url); GNUNET_free (s); } @@ -761,10 +756,11 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, struct Session *pos; for (pos = plugin->head; NULL != pos; pos = pos->next) + { if ((0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) && - (address->address_length == pos->addrlen) && - (0 == memcmp (address->address, pos->addr, pos->addrlen))) + (0 == GNUNET_HELLO_address_cmp(address, pos->address))) return pos; + } return NULL; } @@ -923,14 +919,10 @@ client_receive_mst_cb (void *cls, void *client, atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); atsi.value = s->ats_address_network_type; GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); - delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, - s, (const char *) s->addr, s->addrlen); + delay = s->plugin->env->receive (plugin->env->cls, s->address, s, message); plugin->env->update_address_metrics (plugin->env->cls, - &s->target, - s->addr, - s->addrlen, - s, + s->address, s, &atsi, 1); GNUNET_asprintf (&stat_txt, @@ -949,8 +941,8 @@ client_receive_mst_cb (void *cls, void *client, "Client: peer `%s' address `%s' next read delayed for %s\n", GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - s->plugin->protocol, - s->addr, s->addrlen), + s->plugin->protocol, s->address->address, + s->address->address_length), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); } @@ -1241,8 +1233,8 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static int client_connect_get (struct Session *s) { - CURLMcode mret; + /* create get connection */ s->client_get = curl_easy_init (); s->get.s = s; @@ -1254,16 +1246,21 @@ client_connect_get (struct Session *s) #endif #if BUILD_HTTPS curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); - if (HTTP_OPTIONS_VERIFY_CERTIFICATE == - (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) { - curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); - curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); - } - else - { - curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); + struct HttpAddress *ha; + ha = (struct HttpAddress *) s->address->address; + + if (HTTP_OPTIONS_VERIFY_CERTIFICATE == + (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) + { + curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); + } + else + { + curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); + } } curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); @@ -1334,16 +1331,21 @@ client_connect_put (struct Session *s) #endif #if BUILD_HTTPS curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); - if (HTTP_OPTIONS_VERIFY_CERTIFICATE == - (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) { - curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); - curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); - } - else - { - curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); + struct HttpAddress *ha; + ha = (struct HttpAddress *) s->address->address; + + if (HTTP_OPTIONS_VERIFY_CERTIFICATE == + (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) + { + curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); + } + else + { + curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); + } } curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); @@ -1403,8 +1405,7 @@ client_connect (struct Session *s) /* create url */ if (NULL == http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, s->addrlen)) + plugin->protocol, s->address->address, s->address->address_length)) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, @@ -1414,7 +1415,8 @@ client_connect (struct Session *s) } GNUNET_asprintf (&s->url, "%s/%s;%u", - http_common_plugin_address_to_url (NULL, s->addr, s->addrlen), + http_common_plugin_address_to_url (NULL, s->address->address, + s->address->address_length), GNUNET_i2s_full (plugin->env->my_identity), plugin->last_tag); @@ -1567,9 +1569,7 @@ http_client_plugin_get_session (void *cls, s = GNUNET_new (struct Session); s->target = address->peer; s->plugin = plugin; - s->addr = GNUNET_malloc (address->address_length); - memcpy (s->addr, address->address, address->address_length); - s->addrlen = address->address_length; + s->address = GNUNET_HELLO_address_copy (address); s->ats_address_network_type = ats.value; s->put_paused = GNUNET_NO; s->put_tmp_disconnecting = GNUNET_NO; @@ -1579,8 +1579,9 @@ http_client_plugin_get_session (void *cls, s); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Created new session %p for `%s' address `%s''\n", - s, - http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen), + s, http_common_plugin_address_to_string (NULL, + plugin->protocol, s->address->address, + s->address->address_length), GNUNET_i2s (&s->target)); /* add new session */ @@ -1591,7 +1592,9 @@ http_client_plugin_get_session (void *cls, { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "Cannot connect to peer `%s' address `%s''\n", - http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen), + http_common_plugin_address_to_string (NULL, + plugin->protocol, s->address->address, + s->address->address_length), GNUNET_i2s (&s->target)); client_delete_session (s); return NULL; diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 473516502..c3fa1bba4 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h @@ -59,7 +59,7 @@ #define HTTP_DEFAULT_PORT 80 #define HTTPS_DEFAULT_PORT 443 -enum HTTP_OPTIONS +enum HTTP_ADDRESS_OPTIONS { HTTP_OPTIONS_NONE = 0, HTTP_OPTIONS_VERIFY_CERTIFICATE = 1 diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 15c0323c6..bdc1074ed 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -113,12 +113,7 @@ struct Session /** * Address */ - void *addr; - - /** - * Address length - */ - size_t addrlen; + struct GNUNET_HELLO_Address *address; /** * Unique HTTP/S connection tag for this connection @@ -263,7 +258,7 @@ struct HTTP_Server_Plugin * External hostname the plugin can be connected to, can be different to * the host's FQDN, used e.g. for reverse proxying */ - struct HttpAddress *ext_addr; + struct GNUNET_HELLO_Address *ext_addr; /** * Notify transport only about external address @@ -271,11 +266,6 @@ struct HTTP_Server_Plugin unsigned int external_only; /** - * External address length - */ - size_t ext_addr_len; - - /** * use IPv6 */ uint16_t use_ipv6; @@ -668,8 +658,8 @@ http_server_plugin_address_suggested (void *cls, if ((NULL != plugin->ext_addr) && GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, - plugin->ext_addr, - plugin->ext_addr_len))) + plugin->ext_addr->address, + plugin->ext_addr->address_length))) { /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != @@ -743,7 +733,7 @@ server_delete_session (void *cls, GNUNET_SERVER_mst_destroy (s->msg_tk); s->msg_tk = NULL; } - GNUNET_free (s->addr); + GNUNET_HELLO_address_free (s->address); GNUNET_free_non_null (s->server_recv); GNUNET_free_non_null (s->server_send); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, @@ -1082,10 +1072,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, struct Session *s = NULL; struct ServerConnection *sc = NULL; const union MHD_ConnectionInfo *conn_info; - struct GNUNET_ATS_Information ats; struct HttpAddress *addr; - size_t addr_len; + + struct GNUNET_ATS_Information ats; struct GNUNET_PeerIdentity target; + size_t addr_len; uint32_t tag = 0; int direction = GNUNET_SYSERR; unsigned int to; @@ -1175,8 +1166,8 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, s = GNUNET_new (struct Session); memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); s->plugin = plugin; - s->addr = addr; - s->addrlen = addr_len; + s->address = GNUNET_HELLO_address_allocate (&s->target, PLUGIN_NAME, + addr, addr_len, GNUNET_HELLO_ADDRESS_INFO_INBOUND); s->ats_address_network_type = ats.value; s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; s->tag = tag; @@ -1212,7 +1203,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, if ((NULL != s->server_send) && (NULL != s->server_recv)) { s->connect_in_progress = GNUNET_NO; /* PUT and GET are connected */ - plugin->env->session_start (NULL, &s->target, PLUGIN_NAME, NULL, 0 ,s, NULL, 0); + plugin->env->session_start (NULL, s->address ,s, NULL, 0); } if ((NULL == s->server_recv) || (NULL == s->server_send)) @@ -1353,15 +1344,8 @@ server_receive_mst_cb (void *cls, void *client, atsi.value = s->ats_address_network_type; GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); - - delay = plugin->env->receive (plugin->env->cls, - &s->target, - message, - s, NULL, 0); - - plugin->env->update_address_metrics (plugin->env->cls, - &s->target, - NULL, 0, s, &atsi, 1); + delay = plugin->env->receive (plugin->env->cls, s->address, s, message); + plugin->env->update_address_metrics (plugin->env->cls, s->address, s, &atsi, 1); GNUNET_asprintf (&stat_txt, "# bytes received via %s_server", plugin->protocol); GNUNET_STATISTICS_update (plugin->env->stats, @@ -1376,8 +1360,8 @@ server_receive_mst_cb (void *cls, void *client, "Peer `%s' address `%s' next read delayed for %s\n", GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, s->addrlen), + plugin->protocol, s->address->address, + s->address->address_length), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); } @@ -1485,9 +1469,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, - s->addrlen)); + plugin->protocol, s->address->address, + s->address->address_length)); sc->connected = GNUNET_YES; return MHD_YES; } @@ -1499,9 +1482,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, - s->addrlen)); + plugin->protocol, s->address->address, + s->address->address_length)); sc->connected = GNUNET_NO; /* Sent HTTP/1.1: 200 OK as PUT Response\ */ response = MHD_create_response_from_data (strlen ("Thank you!"), @@ -1519,9 +1501,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, s, sc, GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, - s->addrlen), + plugin->protocol, s->address->address, + s->address->address_length), *upload_data_size); struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); @@ -1597,8 +1578,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, "Peer `%s' connection %p, GET on address `%s' disconnected\n", GNUNET_i2s (&s->target), s->server_send, http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, s->addrlen)); + plugin->protocol, s->address->address, + s->address->address_length)); s->server_send = NULL; if (NULL != (s->server_recv)) { @@ -1617,8 +1598,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, "Peer `%s' connection %p PUT on address `%s' disconnected\n", GNUNET_i2s (&s->target), s->server_recv, http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, s->addrlen)); + plugin->protocol, s->address->address, + s->address->address_length)); s->server_recv = NULL; /* Do not terminate session when PUT disconnects if (NULL != (s->server_send)) @@ -1647,8 +1628,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, "Peer `%s' on address `%s' disconnected\n", GNUNET_i2s (&s->target), http_common_plugin_address_to_string (NULL, - plugin->protocol, - s->addr, s->addrlen)); + plugin->protocol, s->address->address, + s->address->address_length)); if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) { @@ -2217,6 +2198,7 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; struct HttpAddressWrapper *w = NULL; w = GNUNET_new (struct HttpAddressWrapper); @@ -2234,11 +2216,17 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, http_common_plugin_address_to_string (NULL, plugin->protocol, w->address, w->addrlen)); + /* modify our published address list */ #if BUILD_HTTPS - plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); #else - plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); #endif + + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); } @@ -2255,6 +2243,7 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen) { struct HTTP_Server_Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; struct HttpAddressWrapper *w = plugin->addr_head; size_t saddr_len; void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen); @@ -2278,12 +2267,20 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, http_common_plugin_address_to_string (NULL, plugin->protocol, w->address, w->addrlen)); + + GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); + + /* modify our published address list */ #if BUILD_HTTPS - plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); #else - plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); #endif + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); GNUNET_free (w->address); GNUNET_free (w); } @@ -2660,6 +2657,8 @@ static void server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct HTTP_Server_Plugin *plugin = cls; + struct HttpAddress *ext_addr; + size_t ext_addr_len; unsigned int urlen; char *url; @@ -2670,26 +2669,30 @@ server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskCo GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname); urlen = strlen (url) + 1; - plugin->ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); - plugin->ext_addr->options = htonl(plugin->options); - plugin->ext_addr->urlen = htonl (urlen); - plugin->ext_addr_len = sizeof (struct HttpAddress) + urlen; - memcpy (&plugin->ext_addr[1], url, urlen); + ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); + ext_addr->options = htonl(plugin->options); + ext_addr->urlen = htonl (urlen); + ext_addr_len = sizeof (struct HttpAddress) + urlen; + memcpy (&ext_addr[1], url, urlen); GNUNET_free (url); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Notifying transport about external hostname address `%s'\n", plugin->external_hostname); #if BUILD_HTTPS if (GNUNET_YES == plugin->verify_external_hostname) - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, - "Enabling SSL verification for external hostname address `%s'\n", plugin->external_hostname); - plugin->env->notify_address (plugin->env->cls, GNUNET_YES, - plugin->ext_addr, plugin->ext_addr_len, - "https_client"); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, + "Enabling SSL verification for external hostname address `%s'\n", + plugin->external_hostname); + plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE ); + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr); + GNUNET_free (ext_addr); #else - plugin->env->notify_address (plugin->env->cls, GNUNET_YES, - plugin->ext_addr, plugin->ext_addr_len, - "http_client"); + plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE ); + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr); + GNUNET_free (ext_addr); #endif } @@ -3013,21 +3016,19 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) "Notifying transport to remove address `%s'\n", http_common_plugin_address_to_string (NULL, plugin->protocol, - plugin->ext_addr, - plugin->ext_addr_len)); + plugin->ext_addr->address, + plugin->ext_addr->address_length)); #if BUILD_HTTPS plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - plugin->ext_addr, - plugin->ext_addr_len, - "https_client"); + plugin->ext_addr); #else plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - plugin->ext_addr, - plugin->ext_addr_len, - "http_client"); + plugin->ext_addr); #endif + GNUNET_HELLO_address_free (plugin->ext_addr); + plugin->ext_addr = NULL; } /* Stop to report addresses to transport service */ diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index a969bdd22..a2fbc7c8a 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -1,22 +1,22 @@ /* - 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--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. + */ /** * @file transport/plugin_transport_tcp.c * @brief Implementation of the TCP transport service @@ -47,7 +47,6 @@ */ #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - GNUNET_NETWORK_STRUCT_BEGIN /** @@ -72,7 +71,6 @@ struct WelcomeMessage }; - /** * Basically a WELCOME message, but with the purpose * of giving the waiting peer a client handle to use @@ -129,7 +127,6 @@ struct TCPProbeContext struct Plugin *plugin; }; - GNUNET_NETWORK_STRUCT_BEGIN /** @@ -154,7 +151,6 @@ struct IPv4TcpAddress }; - /** * Network format for IPv6 addresses. */ @@ -183,7 +179,6 @@ GNUNET_NETWORK_STRUCT_END */ struct Plugin; - /** * Information kept for each message that is yet to * be transmitted. @@ -232,7 +227,6 @@ struct PendingMessage }; - /** * Session handle for TCP connections. */ @@ -291,19 +285,19 @@ struct Session */ GNUNET_SCHEDULER_TaskIdentifier timeout_task; + struct GNUNET_HELLO_Address *address; + /** * Address of the other peer (either based on our 'connect' * call or on our 'accept' call). * * struct IPv4TcpAddress or struct IPv6TcpAddress */ - void *addr; - + //void *addr; /** * Length of @e addr. */ - size_t addrlen; - + //size_t addrlen; /** * Last activity on this connection. Used to select preferred * connection. @@ -316,11 +310,6 @@ struct Session int expecting_welcome; /** - * Was this a connection that was inbound (we accepted)? (#GNUNET_YES/#GNUNET_NO) - */ - int inbound; - - /** * Was this session created using NAT traversal? */ int is_nat; @@ -331,7 +320,6 @@ struct Session enum GNUNET_ATS_Network_Type ats_address_network_type; }; - /** * Encapsulation of all of the state of the plugin. */ @@ -421,7 +409,6 @@ struct Plugin }; - /** * Function called for a quick conversion of the binary address to * a numeric address. Note that the caller must not free the @@ -434,10 +421,7 @@ struct Plugin * @return string representing the same address */ static const char * -tcp_address_to_string (void *cls, - const void *addr, - size_t addrlen); - +tcp_address_to_string (void *cls, const void *addr, size_t addrlen); /** * Function to check if an inbound connection is acceptable. @@ -453,20 +437,19 @@ tcp_address_to_string (void *cls, */ static int plugin_tcp_access_check (void *cls, - const struct GNUNET_CONNECTION_Credentials *ucred, - const struct sockaddr *addr, socklen_t addrlen) + const struct GNUNET_CONNECTION_Credentials *ucred, + const struct sockaddr *addr, socklen_t addrlen) { struct Plugin *plugin = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Accepting new incoming TCP connection from `%s'\n", - GNUNET_a2s (addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Accepting new incoming TCP connection from `%s'\n", + GNUNET_a2s (addr, addrlen)); if (plugin->cur_connections >= plugin->max_connections) return GNUNET_NO; - plugin->cur_connections ++; + plugin->cur_connections++; return GNUNET_YES; } - /** * Our external IP address/port mapping has changed. * @@ -478,50 +461,51 @@ plugin_tcp_access_check (void *cls, */ static void tcp_nat_port_map_callback (void *cls, int add_remove, - const struct sockaddr *addr, - socklen_t addrlen) + const struct sockaddr *addr, socklen_t addrlen) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; struct IPv4TcpAddress t4; struct IPv6TcpAddress t6; void *arg; size_t args; - LOG (GNUNET_ERROR_TYPE_INFO, - "NAT notification to %s address `%s'\n", - (GNUNET_YES == add_remove) ? "add" : "remove", - GNUNET_a2s (addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_INFO, "NAT notification to %s address `%s'\n", + (GNUNET_YES == add_remove) ? "add" : "remove", + GNUNET_a2s (addr, addrlen)); /* convert 'addr' to our internal format */ switch (addr->sa_family) { case AF_INET: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); - memset (&t4,0, sizeof (t4)); + GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); + memset (&t4, 0, sizeof(t4)); t4.options = htonl (myoptions); t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; arg = &t4; - args = sizeof (t4); + args = sizeof(t4); break; case AF_INET6: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); - memset (&t6, 0, sizeof (t6)); + GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); + memset (&t6, 0, sizeof(t6)); memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, - sizeof (struct in6_addr)); + sizeof(struct in6_addr)); t6.options = htonl (myoptions); t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; arg = &t6; - args = sizeof (t6); + args = sizeof(t6); break; default: - GNUNET_break (0); + GNUNET_break(0); return; } /* modify our published address list */ - plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "tcp"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free(address); } - /** * Function called for a quick conversion of the binary address to * a numeric address. Note that the caller must not free the @@ -549,52 +533,44 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) switch (addrlen) { - case sizeof (struct IPv6TcpAddress): + case sizeof(struct IPv6TcpAddress): t6 = addr; af = AF_INET6; port = ntohs (t6->t6_port); options = ntohl (t6->options); - memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); + memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); sb = &a6; break; - case sizeof (struct IPv4TcpAddress): + case sizeof(struct IPv4TcpAddress): t4 = addr; af = AF_INET; port = ntohs (t4->t4_port); options = ntohl (t4->options); - memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); + memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); sb = &a4; break; case 0: - { - GNUNET_snprintf (rbuf, sizeof (rbuf), "%s", - TRANSPORT_SESSION_INBOUND_STRING); - return rbuf; - } + { + GNUNET_snprintf (rbuf, sizeof(rbuf), "%s", + TRANSPORT_SESSION_INBOUND_STRING); + return rbuf; + } default: - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Unexpected address length: %u bytes\n"), - (unsigned int) addrlen); - return NULL; + 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"); - return NULL; - } - GNUNET_snprintf (rbuf, - sizeof (rbuf), - (af == AF_INET6) - ? "%s.%u.[%s]:%u" - : "%s.%u.%s:%u", - PLUGIN_NAME, - options, - buf, - port); + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); + return NULL ; + } + GNUNET_snprintf (rbuf, sizeof(rbuf), + (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, + buf, port); return rbuf; } - /** * Function called to convert a string address to * a binary address. @@ -608,10 +584,8 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -tcp_string_to_address (void *cls, - const char *addr, - uint16_t addrlen, - void **buf, size_t *added) +tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen, + void **buf, size_t *added) { struct sockaddr_storage socket_address; char *address; @@ -625,82 +599,81 @@ tcp_string_to_address (void *cls, optionstr = NULL; if ((NULL == addr) || (addrlen == 0)) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } if ('\0' != addr[addrlen - 1]) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } if (strlen (addr) != addrlen - 1) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } plugin = GNUNET_strdup (addr); optionstr = strchr (plugin, '.'); if (NULL == optionstr) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } optionstr[0] = '\0'; - optionstr ++; + optionstr++; options = atol (optionstr); address = strchr (optionstr, '.'); if (NULL == address) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } address[0] = '\0'; - address ++; + address++; - if (GNUNET_OK != - GNUNET_STRINGS_to_address_ip (address, strlen (address), - &socket_address)) + if (GNUNET_OK + != GNUNET_STRINGS_to_address_ip (address, strlen (address), + &socket_address)) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } - GNUNET_free (plugin); + GNUNET_free(plugin); switch (socket_address.ss_family) { case AF_INET: - { - struct IPv4TcpAddress *t4; - struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; - t4 = GNUNET_new (struct IPv4TcpAddress); - t4->options = htonl (options); - t4->ipv4_addr = in4->sin_addr.s_addr; - t4->t4_port = in4->sin_port; - *buf = t4; - *added = sizeof (struct IPv4TcpAddress); - return GNUNET_OK; - } + { + struct IPv4TcpAddress *t4; + struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; + t4 = GNUNET_new (struct IPv4TcpAddress); + t4->options = htonl (options); + t4->ipv4_addr = in4->sin_addr.s_addr; + t4->t4_port = in4->sin_port; + *buf = t4; + *added = sizeof(struct IPv4TcpAddress); + return GNUNET_OK; + } case AF_INET6: - { - struct IPv6TcpAddress *t6; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; - t6 = GNUNET_new (struct IPv6TcpAddress); - t6->options = htonl (options); - t6->ipv6_addr = in6->sin6_addr; - t6->t6_port = in6->sin6_port; - *buf = t6; - *added = sizeof (struct IPv6TcpAddress); - return GNUNET_OK; - } + { + struct IPv6TcpAddress *t6; + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; + t6 = GNUNET_new (struct IPv6TcpAddress); + t6->options = htonl (options); + t6->ipv6_addr = in6->sin6_addr; + t6->t6_port = in6->sin6_port; + *buf = t6; + *added = sizeof(struct IPv6TcpAddress); + return GNUNET_OK; + } default: return GNUNET_SYSERR; } } - /** * Closure for #session_lookup_by_client_it(). */ @@ -717,11 +690,9 @@ struct SessionClientCtx struct Session *ret; }; - static int -session_lookup_by_client_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key, + void *value) { struct SessionClientCtx *sc_ctx = cls; struct Session *s = value; @@ -734,7 +705,6 @@ session_lookup_by_client_it (void *cls, return GNUNET_YES; } - /** * Find the session handle for the given client. * Currently uses both the hashmap and the client @@ -747,7 +717,7 @@ session_lookup_by_client_it (void *cls, */ static struct Session * lookup_session_by_client (struct Plugin *plugin, - struct GNUNET_SERVER_Client *client) + struct GNUNET_SERVER_Client *client) { struct Session *ret; struct SessionClientCtx sc_ctx; @@ -756,13 +726,12 @@ lookup_session_by_client (struct Plugin *plugin, sc_ctx.client = client; sc_ctx.ret = NULL; GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, - &session_lookup_by_client_it, &sc_ctx); + &session_lookup_by_client_it, &sc_ctx); /* check both methods yield the same result */ - GNUNET_break (ret == sc_ctx.ret); + GNUNET_break(ret == sc_ctx.ret); return sc_ctx.ret; } - /** * Functions with this signature are called whenever we need * to close a session due to a disconnect or failure to @@ -773,16 +742,15 @@ lookup_session_by_client (struct Plugin *plugin, * @return #GNUNET_OK on success */ static int -tcp_disconnect_session (void *cls, - struct Session *session) +tcp_disconnect_session (void *cls, struct Session *session) { struct Plugin *plugin = cls; struct PendingMessage *pm; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting session of peer `%s' address `%s'\n", - GNUNET_i2s (&session->target), - tcp_address_to_string (NULL, session->addr, session->addrlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Disconnecting session of peer `%s' address `%s'\n", + GNUNET_i2s (&session->target), + tcp_address_to_string (NULL, session->address->address, session->address->address_length)); if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task) { @@ -790,25 +758,20 @@ tcp_disconnect_session (void *cls, session->timeout_task = GNUNET_SCHEDULER_NO_TASK; } - if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, - &session->target, - session)) + if (GNUNET_YES + == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, + &session->target, session)) { GNUNET_STATISTICS_update (session->plugin->env->stats, - gettext_noop ("# TCP sessions active"), -1, - GNUNET_NO); + gettext_noop ("# TCP sessions active"), -1, GNUNET_NO); } else { - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, - &session->target, - session)); + GNUNET_assert( + GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); } if (NULL != session->client) - GNUNET_SERVER_client_set_user_context (session->client, - (void *) NULL); + GNUNET_SERVER_client_set_user_context(session->client, (void *) NULL); /* clean up state */ if (NULL != session->transmit_handle) @@ -817,7 +780,7 @@ tcp_disconnect_session (void *cls, session->transmit_handle = NULL; } session->plugin->env->session_end (session->plugin->env->cls, - &session->target, session); + &session->target, session); if (GNUNET_SCHEDULER_NO_TASK != session->nat_connection_timeout) { @@ -827,26 +790,22 @@ 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)); - GNUNET_STATISTICS_update (session->plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - -(int64_t) pm->message_size, GNUNET_NO); + 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)); GNUNET_STATISTICS_update (session->plugin->env->stats, - gettext_noop - ("# bytes discarded by TCP (disconnect)"), - pm->message_size, GNUNET_NO); - GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, - session->pending_messages_tail, pm); + gettext_noop ("# bytes currently in TCP buffers"), + -(int64_t) pm->message_size, GNUNET_NO); + GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop + ("# bytes discarded by TCP (disconnect)"), pm->message_size, GNUNET_NO); + GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, + session->pending_messages_tail, pm); if (NULL != pm->transmit_cont) - pm->transmit_cont (pm->transmit_cont_cls, &session->target, - GNUNET_SYSERR, pm->message_size, 0); - GNUNET_free (pm); + pm->transmit_cont (pm->transmit_cont_cls, &session->target, GNUNET_SYSERR, + pm->message_size, 0); + GNUNET_free(pm); } - if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) + if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK ) { GNUNET_SCHEDULER_cancel (session->receive_delay_task); if (NULL != session->client) @@ -858,13 +817,12 @@ tcp_disconnect_session (void *cls, GNUNET_SERVER_client_drop (session->client); session->client = NULL; } - GNUNET_free_non_null (session->addr); - GNUNET_assert (NULL == session->transmit_handle); - GNUNET_free (session); + GNUNET_HELLO_address_free(session->address); + GNUNET_assert(NULL == session->transmit_handle); + GNUNET_free(session); return GNUNET_OK; } - /** * Function that is called to get the keepalive factor. * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to @@ -879,7 +837,6 @@ tcp_query_keepalive_factor (void *cls) return 3; } - /** * Session was idle, so disconnect it * @@ -887,22 +844,18 @@ tcp_query_keepalive_factor (void *cls) * @param tc scheduler context */ static void -session_timeout (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *s = cls; s->timeout_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Session %p was idle for %s, disconnecting\n", s, + GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); /* call session destroy function */ tcp_disconnect_session (s->plugin, s); } - /** * Increment session timeout due to activity * @@ -911,19 +864,15 @@ session_timeout (void *cls, static void reschedule_session_timeout (struct Session *s) { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); + GNUNET_assert(GNUNET_SCHEDULER_NO_TASK != s->timeout_task); GNUNET_SCHEDULER_cancel (s->timeout_task); - s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &session_timeout, - s); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout rescheduled for session %p set to %s\n", - s, - GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - GNUNET_YES)); + s->timeout_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, s); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Timeout rescheduled for session %p set to %s\n", s, + GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); } - /** * Create a new session. Also queues a welcome message. * @@ -936,22 +885,20 @@ reschedule_session_timeout (struct Session *s) * @return new session object */ static struct Session * -create_session (struct Plugin *plugin, - const struct GNUNET_PeerIdentity *target, - struct GNUNET_SERVER_Client *client, int is_nat) +create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, + struct GNUNET_SERVER_Client *client, int is_nat) { struct Session *session; struct PendingMessage *pm; struct WelcomeMessage welcome; if (GNUNET_YES != is_nat) - GNUNET_assert (NULL != client); + GNUNET_assert(NULL != client); else - GNUNET_assert (NULL == client); + GNUNET_assert(NULL == client); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new session for peer `%4s'\n", - GNUNET_i2s (target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n", + GNUNET_i2s (target)); session = GNUNET_new (struct Session); session->last_activity = GNUNET_TIME_absolute_get (); session->plugin = plugin; @@ -961,32 +908,29 @@ create_session (struct Plugin *plugin, session->expecting_welcome = GNUNET_YES; session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED; pm = GNUNET_malloc (sizeof (struct PendingMessage) + - sizeof (struct WelcomeMessage)); + sizeof (struct WelcomeMessage)); pm->msg = (const char *) &pm[1]; - pm->message_size = sizeof (struct WelcomeMessage); - welcome.header.size = htons (sizeof (struct WelcomeMessage)); + pm->message_size = sizeof(struct WelcomeMessage); + welcome.header.size = htons (sizeof(struct WelcomeMessage)); welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); welcome.clientIdentity = *plugin->env->my_identity; - memcpy (&pm[1], &welcome, sizeof (welcome)); + memcpy (&pm[1], &welcome, sizeof(welcome)); pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - pm->message_size, GNUNET_NO); - GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, - session->pending_messages_tail, pm); + gettext_noop ("# bytes currently in TCP buffers"), pm->message_size, + GNUNET_NO); + GNUNET_CONTAINER_DLL_insert(session->pending_messages_head, + session->pending_messages_tail, pm); if (GNUNET_YES != is_nat) { GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# TCP sessions active"), 1, - GNUNET_NO); + gettext_noop ("# TCP sessions active"), 1, GNUNET_NO); } - session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, - &session_timeout, - session); + session->timeout_task = GNUNET_SCHEDULER_add_delayed ( + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); return session; } - /** * If we have pending messages, ask the server to * transmit them (schedule the respective tasks, etc.) @@ -996,7 +940,6 @@ create_session (struct Plugin *plugin, static void process_pending_messages (struct Session *session); - /** * Function called to notify a client about the socket * being ready to queue more data. "buf" will be @@ -1025,24 +968,24 @@ do_transmit (void *cls, size_t size, void *buf) plugin = session->plugin; if (NULL == buf) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Timeout trying to transmit to peer `%4s', discarding message queue.\n", - GNUNET_i2s (&session->target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Timeout trying to transmit to peer `%4s', discarding message queue.\n", + GNUNET_i2s (&session->target)); /* timeout; cancel all messages that have already expired */ hd = NULL; tl = NULL; ret = 0; now = GNUNET_TIME_absolute_get (); - while ((NULL != (pos = session->pending_messages_head)) && - (pos->timeout.abs_value_us <= now.abs_value_us)) + while ((NULL != (pos = session->pending_messages_head)) + && (pos->timeout.abs_value_us <= now.abs_value_us)) { - GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, - session->pending_messages_tail, pos); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to transmit %u byte message to `%4s'.\n", - pos->message_size, GNUNET_i2s (&session->target)); + GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, + session->pending_messages_tail, pos); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit %u byte message to `%4s'.\n", pos->message_size, + GNUNET_i2s (&session->target)); ret += pos->message_size; - GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); + GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos); } /* do this call before callbacks (so that if callbacks destroy * session, they have a chance to cancel actions done by this @@ -1053,18 +996,17 @@ do_transmit (void *cls, size_t size, void *buf) * the callbacks may abort the session */ while (NULL != (pos = hd)) { - GNUNET_CONTAINER_DLL_remove (hd, tl, pos); - if (pos->transmit_cont != NULL) - pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR, pos->message_size, 0); - GNUNET_free (pos); + GNUNET_CONTAINER_DLL_remove(hd, tl, pos); + if (pos->transmit_cont != NULL ) + pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR, + pos->message_size, 0); + GNUNET_free(pos); } GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - -(int64_t) ret, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop - ("# bytes discarded by TCP (timeout)"), ret, - GNUNET_NO); + gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, gettext_noop + ("# bytes discarded by TCP (timeout)"), ret, GNUNET_NO); return 0; } /* copy all pending messages that would fit */ @@ -1076,18 +1018,17 @@ do_transmit (void *cls, size_t size, void *buf) { if (ret + pos->message_size > size) break; - GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, - session->pending_messages_tail, pos); - GNUNET_assert (size >= pos->message_size); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Transmitting message of type %u\n", - ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type)); + GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, + session->pending_messages_tail, pos); + GNUNET_assert(size >= pos->message_size); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Transmitting message of type %u\n", + ntohs (((struct GNUNET_MessageHeader * ) pos->msg)->type)); /* FIXME: this memcpy can be up to 7% of our total runtime */ memcpy (cbuf, pos->msg, pos->message_size); cbuf += pos->message_size; ret += pos->message_size; size -= pos->message_size; - GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); + GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos); } /* schedule 'continuation' before callbacks so that callbacks that * cancel everything don't cause us to use a session that no longer @@ -1099,25 +1040,23 @@ do_transmit (void *cls, size_t size, void *buf) * we should not use 'session' after this point */ while (NULL != (pos = hd)) { - GNUNET_CONTAINER_DLL_remove (hd, tl, pos); - if (pos->transmit_cont != NULL) - pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK, pos->message_size, pos->message_size); /* FIXME: include TCP overhead */ - GNUNET_free (pos); + GNUNET_CONTAINER_DLL_remove(hd, tl, pos); + if (pos->transmit_cont != NULL ) + pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK, + pos->message_size, pos->message_size); /* FIXME: include TCP overhead */ + GNUNET_free(pos); } - GNUNET_assert (hd == NULL); - GNUNET_assert (tl == NULL); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n", - ret); + GNUNET_assert(hd == NULL); + GNUNET_assert(tl == NULL); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n", ret); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - -(int64_t) ret, GNUNET_NO); + gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, + GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes transmitted via TCP"), ret, - GNUNET_NO); + gettext_noop ("# bytes transmitted via TCP"), ret, GNUNET_NO); return ret; } - /** * If we have pending messages, ask the server to * transmit them (schedule the respective tasks, etc.) @@ -1129,20 +1068,17 @@ process_pending_messages (struct Session *session) { struct PendingMessage *pm; - GNUNET_assert (NULL != session->client); + GNUNET_assert(NULL != session->client); if (NULL != session->transmit_handle) return; if (NULL == (pm = session->pending_messages_head)) return; - session->transmit_handle = - GNUNET_SERVER_notify_transmit_ready (session->client, pm->message_size, - GNUNET_TIME_absolute_get_remaining - (pm->timeout), &do_transmit, - session); + session->transmit_handle = GNUNET_SERVER_notify_transmit_ready ( + session->client, pm->message_size, + GNUNET_TIME_absolute_get_remaining (pm->timeout), &do_transmit, session); } - #if EXTRA_CHECKS /** * Closure for #session_it(). @@ -1160,7 +1096,6 @@ struct FindSessionContext int res; }; - /** * Function called to check if a session is in our maps. * @@ -1170,9 +1105,7 @@ struct FindSessionContext * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session */ static int -session_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) { struct FindSessionContext *res = cls; struct Session *session = value; @@ -1185,7 +1118,6 @@ session_it (void *cls, return GNUNET_YES; } - /** * Check that the given session is known to the plugin and * is in one of our maps. @@ -1195,30 +1127,28 @@ session_it (void *cls, * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid */ static int -find_session (struct Plugin *plugin, - struct Session *session) +find_session (struct Plugin *plugin, struct Session *session) { struct FindSessionContext session_map_res; struct FindSessionContext nat_map_res; session_map_res.s = session; session_map_res.res = GNUNET_SYSERR; - GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, - &session_it, &session_map_res); + GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it, + &session_map_res); if (GNUNET_SYSERR != session_map_res.res) return GNUNET_OK; nat_map_res.s = session; nat_map_res.res = GNUNET_SYSERR; - GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, - &session_it, &nat_map_res); + GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it, + &nat_map_res); if (GNUNET_SYSERR != nat_map_res.res) return GNUNET_OK; - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } #endif - /** * Function that can be used by the transport service to transmit * a message using the plugin. Note that in the case of a @@ -1247,12 +1177,9 @@ find_session (struct Plugin *plugin, * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -tcp_plugin_send (void *cls, - struct Session *session, - const char *msgbuf, size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) +tcp_plugin_send (void *cls, struct Session *session, const char *msgbuf, + size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct Plugin * plugin = cls; struct PendingMessage *pm; @@ -1260,9 +1187,8 @@ tcp_plugin_send (void *cls, #if EXTRA_CHECKS if (GNUNET_SYSERR == find_session (plugin, session)) { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Trying to send with invalid session %p\n")); - GNUNET_assert (0); + LOG(GNUNET_ERROR_TYPE_ERROR, _("Trying to send with invalid session %p\n")); + GNUNET_assert(0); return GNUNET_SYSERR; } #endif @@ -1275,63 +1201,55 @@ tcp_plugin_send (void *cls, pm->transmit_cont = cont; pm->transmit_cont_cls = cont_cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Asked to transmit %u bytes to `%s', added message to list.\n", - msgbuf_size, GNUNET_i2s (&session->target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Asked to transmit %u bytes to `%s', added message to list.\n", + msgbuf_size, GNUNET_i2s (&session->target)); - if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, - &session->target, - session)) + if (GNUNET_YES + == GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, session)) { - GNUNET_assert (NULL != session->client); + GNUNET_assert(NULL != session->client); GNUNET_SERVER_client_set_timeout (session->client, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - msgbuf_size, GNUNET_NO); + gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, + GNUNET_NO); /* append pm to pending_messages list */ - GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, - session->pending_messages_tail, pm); + GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, + session->pending_messages_tail, pm); process_pending_messages (session); return msgbuf_size; } - else if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, - &session->target, - session)) + else if (GNUNET_YES + == GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, + &session->target, session)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "This NAT WAIT session for peer `%s' is not yet ready!\n", - GNUNET_i2s (&session->target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "This NAT WAIT session for peer `%s' is not yet ready!\n", + GNUNET_i2s (&session->target)); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes currently in TCP buffers"), - msgbuf_size, GNUNET_NO); + gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, + GNUNET_NO); /* append pm to pending_messages list */ - GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, - session->pending_messages_tail, pm); + GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, + session->pending_messages_tail, pm); return msgbuf_size; } else { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Invalid session %p\n", session); + LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); if (NULL != cont) - cont (cont_cls, - &session->target, - GNUNET_SYSERR, - pm->message_size, - 0); - GNUNET_break (0); - GNUNET_free (pm); + cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); + GNUNET_break(0); + GNUNET_free(pm); return GNUNET_SYSERR; /* session does not exist here */ } } - /** * Closure for #session_lookup_it(). */ @@ -1340,19 +1258,14 @@ struct SessionItCtx /** * Address we are looking for. */ - void *addr; - - /** - * Number of bytes in @e addr. - */ - size_t addrlen; + const struct GNUNET_HELLO_Address *address; /** * Where to store the session (if we found it). */ struct Session *result; -}; +}; /** * Look for a session by address. @@ -1363,23 +1276,19 @@ struct SessionItCtx * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session */ static int -session_lookup_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_lookup_it (void *cls, const struct GNUNET_PeerIdentity *key, + void *value) { struct SessionItCtx * si_ctx = cls; struct Session * session = value; - if (session->addrlen != si_ctx->addrlen) - return GNUNET_YES; - if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen)) + if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) return GNUNET_YES; /* Found existing session */ si_ctx->result = session; return GNUNET_NO; } - /** * Task cleaning up a NAT connection attempt after timeout * @@ -1387,26 +1296,21 @@ session_lookup_it (void *cls, * @param tc scheduler context (unused) */ static void -nat_connect_timeout (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *session = cls; session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", - GNUNET_i2s (&session->target), - tcp_address_to_string (NULL, - session->addr, session->addrlen)); - tcp_disconnect_session (session->plugin, - session); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", + GNUNET_i2s (&session->target), + tcp_address_to_string (NULL, session->address->address, session->address->address_length)); + tcp_disconnect_session (session->plugin, session); } - static void tcp_plugin_update_session_timeout (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct Session *session) + const struct GNUNET_PeerIdentity *peer, struct Session *session) { struct Plugin *plugin = cls; @@ -1415,7 +1319,6 @@ tcp_plugin_update_session_timeout (void *cls, reschedule_session_timeout (session); } - /** * Create a new session to transmit data to the target * This session will used to send data to this peer and the plugin will @@ -1426,8 +1329,7 @@ tcp_plugin_update_session_timeout (void *cls, * @return the session if the address is valid, NULL otherwise */ static struct Session * -tcp_plugin_get_session (void *cls, - const struct GNUNET_HELLO_Address *address) +tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) { struct Plugin *plugin = cls; struct Session *session = NULL; @@ -1444,48 +1346,44 @@ tcp_plugin_get_session (void *cls, size_t addrlen; addrlen = address->address_length; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to get session for `%s' address of peer `%s'\n", - tcp_address_to_string(NULL, address->address, address->address_length), - GNUNET_i2s (&address->peer)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Trying to get session for `%s' address of peer `%s'\n", + tcp_address_to_string(NULL, address->address, address->address_length), + GNUNET_i2s (&address->peer)); /* look for existing session */ - if (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, - &address->peer)) + if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, + &address->peer)) { struct SessionItCtx si_ctx; - si_ctx.addr = (void *) address->address; - si_ctx.addrlen = address->address_length; - + si_ctx.address = address; si_ctx.result = NULL; GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, - &address->peer, - &session_lookup_it, &si_ctx); - if (si_ctx.result != NULL) + &address->peer, &session_lookup_it, &si_ctx); + if (si_ctx.result != NULL ) { session = si_ctx.result; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing session for `%s' address `%s' session %p\n", - GNUNET_i2s (&address->peer), - tcp_address_to_string(NULL, address->address, address->address_length), - session); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Found existing session for `%s' address `%s' session %p\n", + GNUNET_i2s (&address->peer), + tcp_address_to_string(NULL, address->address, address->address_length), + session); return session; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Existing sessions did not match address `%s' or peer `%s'\n", - tcp_address_to_string(NULL, address->address, address->address_length), - GNUNET_i2s (&address->peer)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Existing sessions did not match address `%s' or peer `%s'\n", + tcp_address_to_string(NULL, address->address, address->address_length), + GNUNET_i2s (&address->peer)); } - if (addrlen == sizeof (struct IPv6TcpAddress)) + if (addrlen == sizeof(struct IPv6TcpAddress)) { - GNUNET_assert (NULL != address->address); /* make static analysis happy */ + GNUNET_assert(NULL != address->address); /* make static analysis happy */ t6 = address->address; af = AF_INET6; - memset (&a6, 0, sizeof (a6)); + memset (&a6, 0, sizeof(a6)); #if HAVE_SOCKADDR_IN_SIN_LEN a6.sin6_len = sizeof (a6); #endif @@ -1493,16 +1391,16 @@ tcp_plugin_get_session (void *cls, a6.sin6_port = t6->t6_port; if (t6->t6_port == 0) is_natd = GNUNET_YES; - memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); + memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); sb = &a6; - sbs = sizeof (a6); + sbs = sizeof(a6); } - else if (addrlen == sizeof (struct IPv4TcpAddress)) + else if (addrlen == sizeof(struct IPv4TcpAddress)) { - GNUNET_assert (NULL != address->address); /* make static analysis happy */ + GNUNET_assert(NULL != address->address); /* make static analysis happy */ t4 = address->address; af = AF_INET; - memset (&a4, 0, sizeof (a4)); + memset (&a4, 0, sizeof(a4)); #if HAVE_SOCKADDR_IN_SIN_LEN a4.sin_len = sizeof (a4); #endif @@ -1512,144 +1410,123 @@ tcp_plugin_get_session (void *cls, is_natd = GNUNET_YES; a4.sin_addr.s_addr = t4->ipv4_addr; sb = &a4; - sbs = sizeof (a4); + sbs = sizeof(a4); } else { - GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop - ("# requests to create session with invalid address"), - 1, GNUNET_NO); - return NULL; + GNUNET_STATISTICS_update (plugin->env->stats, gettext_noop + ("# requests to create session with invalid address"), 1, GNUNET_NO); + return NULL ; } ats = plugin->env->get_address_type (plugin->env->cls, sb, sbs); - if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) + if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) { /* NAT client only works with IPv4 addresses */ - return NULL; + return NULL ; } if (plugin->cur_connections >= plugin->max_connections) { /* saturated */ - return NULL; + return NULL ; } - if ((is_natd == GNUNET_YES) && - (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, - &address->peer))) + if ((is_natd == GNUNET_YES) + && (GNUNET_YES + == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) { /* Only do one NAT punch attempt per peer identity */ - return NULL; + return NULL ; } if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && - (GNUNET_NO == - GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, - &address->peer))) + (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, + &address->peer))) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found valid IPv4 NAT address (creating session)!\n") ; - session = create_session (plugin, - &address->peer, - NULL, - GNUNET_YES); - session->addrlen = 0; - session->addr = NULL; - session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); - GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); + "Found valid IPv4 NAT address (creating session)!\n"); + session = create_session (plugin, &address->peer, NULL, GNUNET_YES); + session->address = GNUNET_HELLO_address_copy (address); + session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( + ats.value); + GNUNET_break( + session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, - &nat_connect_timeout, - session); - GNUNET_assert (session != NULL); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, - &session->target, - session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + &nat_connect_timeout, session); + GNUNET_assert(session != NULL); + GNUNET_assert( + GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Created NAT WAIT connection to `%4s' at `%s'\n", - GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Created NAT WAIT connection to `%4s' at `%s'\n", + GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) return session; else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Running NAT client for `%4s' at `%s' failed\n", - GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Running NAT client for `%4s' at `%s' failed\n", + GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); tcp_disconnect_session (plugin, session); - return NULL; + return NULL ; } } /* create new outbound session */ - GNUNET_assert (plugin->cur_connections <= plugin->max_connections); + GNUNET_assert(plugin->cur_connections <= plugin->max_connections); sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); if (NULL == sa) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to create connection to `%4s' at `%s'\n", - GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); - return NULL; + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Failed to create connection to `%4s' at `%s'\n", + GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); + return NULL ; } plugin->cur_connections++; if (plugin->cur_connections == plugin->max_connections) GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", - GNUNET_i2s (&address->peer), - GNUNET_a2s (sb, sbs)); - - session = create_session (plugin, - &address->peer, - GNUNET_SERVER_connect_socket (plugin->server, sa), - GNUNET_NO); - session->addr = GNUNET_malloc (addrlen); - memcpy (session->addr, address->address, addrlen); - session->addrlen = addrlen; - session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); - GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); - GNUNET_SERVER_client_set_user_context (session->client, session); - GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, - &session->target, - session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new session for `%s' address `%s' session %p\n", - GNUNET_i2s (&address->peer), - tcp_address_to_string(NULL, address->address, address->address_length), - session); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", + GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); + + session = create_session (plugin, &address->peer, + GNUNET_SERVER_connect_socket (plugin->server, sa), GNUNET_NO); + session->address = GNUNET_HELLO_address_copy (address); + session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( + ats.value); + GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); + GNUNET_SERVER_client_set_user_context(session->client, session); + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, + session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Creating new session for `%s' address `%s' session %p\n", + GNUNET_i2s (&address->peer), + tcp_address_to_string(NULL, address->address, address->address_length), + session); /* Send TCP Welcome */ process_pending_messages (session); return session; } - static int -session_disconnect_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +session_disconnect_it (void *cls, const struct GNUNET_PeerIdentity *key, + void *value) { struct Plugin *plugin = cls; struct Session *session = value; - GNUNET_STATISTICS_update (session->plugin->env->stats, - gettext_noop - ("# transport-service disconnect requests for TCP"), - 1, GNUNET_NO); - tcp_disconnect_session (plugin, - session); + GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop + ("# transport-service disconnect requests for TCP"), 1, GNUNET_NO); + tcp_disconnect_session (plugin, session); return GNUNET_YES; } - /** * Function that can be called to force a disconnect from the * specified neighbour. This should also cancel all previously @@ -1667,21 +1544,18 @@ session_disconnect_it (void *cls, * to be cancelled */ static void -tcp_plugin_disconnect (void *cls, - const struct GNUNET_PeerIdentity *target) +tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting peer `%4s'\n", - GNUNET_i2s (target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s'\n", + GNUNET_i2s (target)); GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, target, - &session_disconnect_it, plugin); + &session_disconnect_it, plugin); GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, target, - &session_disconnect_it, plugin); + &session_disconnect_it, plugin); } - /** * Running pretty printers: head */ @@ -1743,10 +1617,8 @@ struct PrettyPrinterContext uint32_t options; }; - static void -ppc_cancel_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PrettyPrinterContext *ppc = cls; @@ -1756,11 +1628,10 @@ ppc_cancel_task (void *cls, 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); + GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); + GNUNET_free(ppc); } - /** * Append our port and forward the result. * @@ -1776,12 +1647,12 @@ append_port (void *cls, const char *hostname) if (NULL == hostname) { - ppc->asc (ppc->asc_cls, NULL); - GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); + ppc->asc (ppc->asc_cls, NULL ); + GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); GNUNET_SCHEDULER_cancel (ppc->timeout_task); ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; ppc->resolver_handle = NULL; - GNUNET_free (ppc); + GNUNET_free(ppc); return; } for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) @@ -1789,29 +1660,20 @@ append_port (void *cls, const char *hostname) break; if (NULL == cur) { - GNUNET_break (0); + 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); + GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, + ppc->port); ppc->asc (ppc->asc_cls, ret); - GNUNET_free (ret); + GNUNET_free(ret); } - /** * Convert the transports address to a nice, human-readable * format. @@ -1828,11 +1690,9 @@ append_port (void *cls, const char *hostname) */ 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) + 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; @@ -1844,45 +1704,45 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, uint16_t port; uint32_t options; - if (addrlen == sizeof (struct IPv6TcpAddress)) + if (addrlen == sizeof(struct IPv6TcpAddress)) { t6 = addr; - memset (&a6, 0, sizeof (a6)); + memset (&a6, 0, sizeof(a6)); a6.sin6_family = AF_INET6; a6.sin6_port = t6->t6_port; - memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); + memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); port = ntohs (t6->t6_port); options = ntohl (t6->options); sb = &a6; - sbs = sizeof (a6); + sbs = sizeof(a6); } - else if (addrlen == sizeof (struct IPv4TcpAddress)) + else if (addrlen == sizeof(struct IPv4TcpAddress)) { t4 = addr; - memset (&a4, 0, sizeof (a4)); + memset (&a4, 0, sizeof(a4)); a4.sin_family = AF_INET; a4.sin_port = t4->t4_port; a4.sin_addr.s_addr = t4->ipv4_addr; port = ntohs (t4->t4_port); options = ntohl (t4->options); sb = &a4; - sbs = sizeof (a4); + sbs = sizeof(a4); } else if (0 == addrlen) { asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); - asc (asc_cls, NULL); + asc (asc_cls, NULL ); return; } else { /* invalid address */ - GNUNET_break_op (0); - asc (asc_cls, NULL); + GNUNET_break_op(0); + asc (asc_cls, NULL ); return; } ppc = GNUNET_new (struct PrettyPrinterContext); - if (addrlen == sizeof (struct IPv6TcpAddress)) + if (addrlen == sizeof(struct IPv6TcpAddress)) ppc->ipv6 = GNUNET_YES; else ppc->ipv6 = GNUNET_NO; @@ -1890,24 +1750,22 @@ 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->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); + timeout, &append_port, ppc); if (NULL != ppc->resolver_handle) { //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding request %p\n", ppc); - GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); + GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); } else { - GNUNET_break (0); - GNUNET_free (ppc); + GNUNET_break(0); + GNUNET_free(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 @@ -1926,7 +1784,6 @@ check_port (struct Plugin *plugin, uint16_t in_port) return GNUNET_SYSERR; } - /** * Function that will be called to check if a binary address for this * plugin is well-formed and corresponds to an address for THIS peer @@ -1949,26 +1806,26 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) struct IPv4TcpAddress *v4; struct IPv6TcpAddress *v6; - if ((addrlen != sizeof (struct IPv4TcpAddress)) && - (addrlen != sizeof (struct IPv6TcpAddress))) + if ((addrlen != sizeof(struct IPv4TcpAddress)) + && (addrlen != sizeof(struct IPv6TcpAddress))) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (addrlen == sizeof (struct IPv4TcpAddress)) + if (addrlen == sizeof(struct IPv4TcpAddress)) { v4 = (struct IPv4TcpAddress *) addr; - if (0 != memcmp (&v4->options, &myoptions, sizeof (myoptions))) + if (0 != memcmp (&v4->options, &myoptions, sizeof(myoptions))) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) return GNUNET_SYSERR; - if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, - sizeof (struct in_addr))) + if (GNUNET_OK + != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, + sizeof(struct in_addr))) return GNUNET_SYSERR; } else @@ -1976,25 +1833,24 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) v6 = (struct IPv6TcpAddress *) addr; if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (0 != memcmp (&v6->options, &myoptions, sizeof (myoptions))) + if (0 != memcmp (&v6->options, &myoptions, sizeof(myoptions))) { - GNUNET_break (0); - return GNUNET_SYSERR; + GNUNET_break(0); + return GNUNET_SYSERR; } if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) return GNUNET_SYSERR; - if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, - sizeof (struct in6_addr))) + if (GNUNET_OK + != GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, + sizeof(struct in6_addr))) return GNUNET_SYSERR; } return GNUNET_OK; } - /** * We've received a nat probe from this peer via TCP. Finish * creating the client session and resume sending of queued @@ -2005,9 +1861,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) * @param message the actual message */ static void -handle_tcp_nat_probe (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; struct Session *session; @@ -2019,45 +1874,40 @@ handle_tcp_nat_probe (void *cls, const struct sockaddr_in *s4; const struct sockaddr_in6 *s6; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received NAT probe\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); /* We have received a TCP NAT probe, meaning we (hopefully) initiated * a connection to this peer by running gnunet-nat-client. This peer * received the punch message and now wants us to use the new connection * as the default for that peer. Do so and then send a WELCOME message * so we can really be connected! */ - if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage)) + if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) { - GNUNET_break_op (0); + GNUNET_break_op(0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; - if (0 == - memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, - sizeof (struct GNUNET_PeerIdentity))) + if (0 == memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity))) { /* refuse connections from ourselves */ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - session = - GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, - &tcp_nat_probe->clientIdentity); - if (session == NULL) + session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, + &tcp_nat_probe->clientIdentity); + if (session == NULL ) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Did NOT find session for NAT probe!\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found session for NAT probe!\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); - if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK) + if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK ) { GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; @@ -2065,24 +1915,19 @@ handle_tcp_nat_probe (void *cls, if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - GNUNET_break (0); + GNUNET_break(0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); tcp_disconnect_session (plugin, session); return; } - GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove - (plugin->nat_wait_conns, - &tcp_nat_probe->clientIdentity, - session) == GNUNET_YES); - GNUNET_SERVER_client_set_user_context (client, session); - GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, - &session->target, session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + GNUNET_assert( + GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &tcp_nat_probe->clientIdentity, session) == GNUNET_YES); + GNUNET_SERVER_client_set_user_context(client, session); + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, + session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); session->last_activity = GNUNET_TIME_absolute_get (); - session->inbound = GNUNET_NO; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found address `%s' for incoming connection\n", - GNUNET_a2s (vaddr, alen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Found address `%s' for incoming connection\n", + GNUNET_a2s (vaddr, alen)); switch (((const struct sockaddr *) vaddr)->sa_family) { case AF_INET: @@ -2091,39 +1936,38 @@ handle_tcp_nat_probe (void *cls, t4->options = 0; t4->t4_port = s4->sin_port; t4->ipv4_addr = s4->sin_addr.s_addr; - session->addr = t4; - session->addrlen = sizeof (struct IPv4TcpAddress); + session->address = GNUNET_HELLO_address_allocate ( + &tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t4, + sizeof(struct IPv4TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); break; case AF_INET6: s6 = vaddr; t6 = GNUNET_new (struct IPv6TcpAddress); t6->options = 0; t6->t6_port = s6->sin6_port; - memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); - session->addr = t6; - session->addrlen = sizeof (struct IPv6TcpAddress); + memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); + session->address = GNUNET_HELLO_address_allocate ( + &tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t6, + sizeof(struct IPv6TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); break; default: - GNUNET_break_op (0); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Bad address for incoming connection!\n"); - GNUNET_free (vaddr); + GNUNET_break_op(0); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); + GNUNET_free(vaddr); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); tcp_disconnect_session (plugin, session); return; } - GNUNET_free (vaddr); - GNUNET_break (NULL == session->client); + GNUNET_free(vaddr); + GNUNET_break(NULL == session->client); GNUNET_SERVER_client_keep (client); session->client = client; GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# TCP sessions active"), 1, - GNUNET_NO); + gettext_noop ("# TCP sessions active"), 1, GNUNET_NO); process_pending_messages (session); GNUNET_SERVER_receive_done (client, GNUNET_OK); } - /** * We've received a welcome from this peer via TCP. Possibly create a * fresh client record and send back our welcome. @@ -2134,135 +1978,120 @@ handle_tcp_nat_probe (void *cls, */ static void handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; struct Session *session; size_t alen; void *vaddr; - struct IPv4TcpAddress *t4; - struct IPv6TcpAddress *t6; + struct IPv4TcpAddress t4; + struct IPv6TcpAddress t6; const struct sockaddr_in *s4; const struct sockaddr_in6 *s6; struct GNUNET_ATS_Information ats; - if (0 == - memcmp (&wm->clientIdentity, plugin->env->my_identity, - sizeof (struct GNUNET_PeerIdentity))) + if (0 == memcmp (&wm->clientIdentity, plugin->env->my_identity, + sizeof(struct GNUNET_PeerIdentity))) { /* refuse connections from ourselves */ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Received %s message from my own identity `%4s' on address `%s'\n", - "WELCOME", GNUNET_i2s (&wm->clientIdentity), GNUNET_a2s (vaddr, alen)); - GNUNET_free (vaddr); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Received %s message from my own identity `%4s' on address `%s'\n", + "WELCOME", GNUNET_i2s (&wm->clientIdentity), + GNUNET_a2s (vaddr, alen)); + GNUNET_free(vaddr); } - GNUNET_break_op (0); + GNUNET_break_op(0); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received %s message from `%4s' %p\n", "WELCOME", - GNUNET_i2s (&wm->clientIdentity), client); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Received %s message from `%4s' %p\n", "WELCOME", + GNUNET_i2s (&wm->clientIdentity), client); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# TCP WELCOME messages received"), 1, - GNUNET_NO); + gettext_noop ("# TCP WELCOME messages received"), 1, GNUNET_NO); session = lookup_session_by_client (plugin, client); if (NULL != session) { - if (GNUNET_OK == - GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) + if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing session %p for peer `%s'\n", - session, - GNUNET_a2s (vaddr, alen)); - GNUNET_free (vaddr); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for peer `%s'\n", + session, GNUNET_a2s (vaddr, alen)); + GNUNET_free(vaddr); } } else { GNUNET_SERVER_client_keep (client); if (NULL != plugin->service) /* Otherwise value is incremented in tcp_access_check */ - plugin->cur_connections++; + plugin->cur_connections++; if (plugin->cur_connections == plugin->max_connections) - GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ + GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO); - session->inbound = GNUNET_YES; if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) { - if (alen == sizeof (struct sockaddr_in)) + if (alen == sizeof(struct sockaddr_in)) { s4 = vaddr; - t4 = GNUNET_new (struct IPv4TcpAddress); - t4->options = htonl (0); - t4->t4_port = s4->sin_port; - t4->ipv4_addr = s4->sin_addr.s_addr; - session->addr = t4; - session->addrlen = sizeof (struct IPv4TcpAddress); + memset (&t4, '\0', sizeof (t4)); + t4.options = htonl (0); + t4.t4_port = s4->sin_port; + t4.ipv4_addr = s4->sin_addr.s_addr; + session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, + PLUGIN_NAME, &t4, sizeof(struct IPv4TcpAddress), + GNUNET_HELLO_ADDRESS_INFO_INBOUND); } - else if (alen == sizeof (struct sockaddr_in6)) + else if (alen == sizeof(struct sockaddr_in6)) { s6 = vaddr; - t6 = GNUNET_new (struct IPv6TcpAddress); - t6->options = htonl (0); - t6->t6_port = s6->sin6_port; - memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); - session->addr = t6; - session->addrlen = sizeof (struct IPv6TcpAddress); + memset (&t6, '\0', sizeof (t6)); + t6.options = htonl (0); + t6.t6_port = s6->sin6_port; + memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); + session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, + PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress), + GNUNET_HELLO_ADDRESS_INFO_INBOUND); } - ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); - session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new session %p for peer `%s'\n", - session, - GNUNET_a2s (vaddr, alen)); - GNUNET_free (vaddr); - GNUNET_SERVER_client_set_user_context (session->client, session); - GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, - &session->target, - session, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); + ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); + session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( + ats.value); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session %p for peer `%s'\n", + session, GNUNET_a2s (vaddr, alen)); + GNUNET_free(vaddr); + GNUNET_SERVER_client_set_user_context(session->client, session); + GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, + session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); } else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Did not obtain TCP socket address for incoming connection\n"); - GNUNET_break (0); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Did not obtain TCP socket address for incoming connection\n"); + GNUNET_break(0); } } if (session->expecting_welcome != GNUNET_YES) { - GNUNET_break_op (0); + GNUNET_break_op(0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); - GNUNET_break (0); + GNUNET_break(0); return; } session->last_activity = GNUNET_TIME_absolute_get (); session->expecting_welcome = GNUNET_NO; /* Notify transport and ATS about new session */ - if (GNUNET_YES == session->inbound) - { - plugin->env->session_start (NULL, - &wm->clientIdentity, - PLUGIN_NAME, - (GNUNET_YES == session->inbound) ? NULL : session->addr, - (GNUNET_YES == session->inbound) ? 0 : session->addrlen, - session, &ats, 1); - } + plugin->env->session_start (NULL, session->address, session, &ats, 1); + process_pending_messages (session); GNUNET_SERVER_client_set_timeout (client, - GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); GNUNET_SERVER_receive_done (client, GNUNET_OK); } - /** * Task to signal the server that we can continue * receiving from the TCP client now. @@ -2271,8 +2100,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, * @param tc task context (unused) */ static void -delayed_done (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *session = cls; @@ -2282,7 +2110,6 @@ delayed_done (void *cls, GNUNET_SERVER_receive_done (session->client, GNUNET_OK); } - /** * We've received data for this peer via TCP. Unbox, * compute latency and forward. @@ -2293,7 +2120,7 @@ delayed_done (void *cls, */ static void handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { struct Plugin *plugin = cls; struct Session *session; @@ -2301,8 +2128,8 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, uint16_t type; type = ntohs (message->type); - if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || - (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) + if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) + || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) { /* We don't want to propagate WELCOME and NAT Probe messages up! */ GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -2316,12 +2143,11 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, size_t alen; GNUNET_SERVER_client_get_address (client, &vaddr, &alen); - LOG (GNUNET_ERROR_TYPE_ERROR, - "Received unexpected %u bytes of type %u from `%s'\n", - (unsigned int) ntohs (message->size), - (unsigned int) ntohs (message->type), - GNUNET_a2s(vaddr, alen)); - GNUNET_break_op (0); + LOG(GNUNET_ERROR_TYPE_ERROR, + "Received unexpected %u bytes of type %u from `%s'\n", + (unsigned int ) ntohs (message->size), + (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); + GNUNET_break_op(0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); GNUNET_free_non_null(vaddr); return; @@ -2333,48 +2159,38 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, size_t alen; GNUNET_SERVER_client_get_address (client, &vaddr, &alen); - LOG (GNUNET_ERROR_TYPE_ERROR, - "Received unexpected %u bytes of type %u from `%s'\n", - (unsigned int) ntohs (message->size), - (unsigned int) ntohs (message->type), - GNUNET_a2s(vaddr, alen)); - GNUNET_break_op (0); + LOG(GNUNET_ERROR_TYPE_ERROR, + "Received unexpected %u bytes of type %u from `%s'\n", + (unsigned int ) ntohs (message->size), + (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); + GNUNET_break_op(0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); GNUNET_free_non_null(vaddr); return; } session->last_activity = GNUNET_TIME_absolute_get (); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Passing %u bytes of type %u from `%4s' to transport service.\n", - (unsigned int) ntohs (message->size), - (unsigned int) ntohs (message->type), - GNUNET_i2s (&session->target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Passing %u bytes of type %u from `%4s' to transport service.\n", + (unsigned int ) ntohs (message->size), + (unsigned int ) ntohs (message->type), GNUNET_i2s (&session->target)); GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop ("# bytes received via TCP"), - ntohs (message->size), GNUNET_NO); + gettext_noop ("# bytes received via TCP"), ntohs (message->size), + GNUNET_NO); struct GNUNET_ATS_Information distance; distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); distance.value = htonl ((uint32_t) session->ats_address_network_type); - GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); - - GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, - &session->target, - session)); - - delay = plugin->env->receive (plugin->env->cls, - &session->target, - message, - session, - (GNUNET_YES == session->inbound) ? NULL : session->addr, - (GNUNET_YES == session->inbound) ? 0 : session->addrlen); - plugin->env->update_address_metrics (plugin->env->cls, - &session->target, - (GNUNET_YES == session->inbound) ? NULL : session->addr, - (GNUNET_YES == session->inbound) ? 0 : session->addrlen, - session, &distance, 1); + GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); + + GNUNET_assert( + GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, + &session->target, session)); + + delay = plugin->env->receive (plugin->env->cls, session->address, session, message); + plugin->env->update_address_metrics (plugin->env->cls, session->address, + session, &distance, 1); reschedule_session_timeout (session); if (0 == delay.rel_value_us) { @@ -2382,17 +2198,15 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, } else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Throttling receiving from `%s' for %s\n", - GNUNET_i2s (&session->target), - GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Throttling receiving from `%s' for %s\n", + GNUNET_i2s (&session->target), + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); GNUNET_SERVER_disable_receive_done_warning (client); - session->receive_delay_task = - GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); + session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, + &delayed_done, session); } } - /** * Functions with this signature are called whenever a peer * is disconnected on the network level. @@ -2406,36 +2220,30 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) struct Plugin *plugin = cls; struct Session *session; - if (client == NULL) + if (client == NULL ) return; session = lookup_session_by_client (plugin, client); - if (session == NULL) - return; /* unknown, nothing to do */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroying session of `%4s' with %s due to network-level disconnect.\n", - GNUNET_i2s (&session->target), - (session->addr != - NULL) ? tcp_address_to_string (session->plugin, - session->addr, - session->addrlen) : - "*"); + if (session == NULL ) + return; /* unknown, nothing to do */ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Destroying session of `%4s' with %s due to network-level disconnect.\n", + GNUNET_i2s (&session->target), + tcp_address_to_string (session->plugin, session->address->address, + session->address->address_length)); if (plugin->cur_connections == plugin->max_connections) GNUNET_SERVER_resume (plugin->server); /* Resume server */ if (plugin->cur_connections < 1) - GNUNET_break (0); + GNUNET_break(0); else plugin->cur_connections--; - GNUNET_STATISTICS_update (session->plugin->env->stats, - gettext_noop - ("# network-level TCP disconnect events"), 1, - GNUNET_NO); + GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop + ("# network-level TCP disconnect events"), 1, GNUNET_NO); tcp_disconnect_session (plugin, session); } - /** * We can now send a probe message, copy into buffer to really send. * @@ -2452,24 +2260,23 @@ notify_send_probe (void *cls, size_t size, void *buf) size_t ret; tcp_probe_ctx->transmit_handle = NULL; - GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, - tcp_probe_ctx); - if (buf == NULL) + GNUNET_CONTAINER_DLL_remove(plugin->probe_head, plugin->probe_tail, + tcp_probe_ctx); + if (buf == NULL ) { GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); - GNUNET_free (tcp_probe_ctx); + GNUNET_free(tcp_probe_ctx); return 0; } - GNUNET_assert (size >= sizeof (tcp_probe_ctx->message)); - memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message)); + GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); + memcpy (buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, - tcp_probe_ctx->sock); - ret = sizeof (tcp_probe_ctx->message); - GNUNET_free (tcp_probe_ctx); + tcp_probe_ctx->sock); + ret = sizeof(tcp_probe_ctx->message); + GNUNET_free(tcp_probe_ctx); return ret; } - /** * Function called by the NAT subsystem suggesting another peer wants * to connect to us via connection reversal. Try to connect back to the @@ -2481,7 +2288,7 @@ notify_send_probe (void *cls, size_t size, void *buf) */ static void try_connection_reversal (void *cls, const struct sockaddr *addr, - socklen_t addrlen) + socklen_t addrlen) { struct Plugin *plugin = cls; struct GNUNET_CONNECTION_Handle *sock; @@ -2492,7 +2299,7 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, * that wants to connect to us! Send a message to establish a connection. */ sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); - if (sock == NULL) + if (sock == NULL ) { /* failed for some odd reason (out of sockets?); ignore attempt */ return; @@ -2501,27 +2308,22 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, /* FIXME: do we need to track these probe context objects so that * we can clean them up on plugin unload? */ tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); - tcp_probe_ctx->message.header.size = - htons (sizeof (struct TCP_NAT_ProbeMessage)); - tcp_probe_ctx->message.header.type = - htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); + tcp_probe_ctx->message.header.size = htons ( + sizeof(struct TCP_NAT_ProbeMessage)); + tcp_probe_ctx->message.header.type = htons ( + GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, - sizeof (struct GNUNET_PeerIdentity)); + sizeof(struct GNUNET_PeerIdentity)); tcp_probe_ctx->plugin = plugin; tcp_probe_ctx->sock = sock; - GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail, - tcp_probe_ctx); - tcp_probe_ctx->transmit_handle = - GNUNET_CONNECTION_notify_transmit_ready (sock, - ntohs (tcp_probe_ctx-> - message.header.size), - GNUNET_TIME_UNIT_FOREVER_REL, - ¬ify_send_probe, - tcp_probe_ctx); + GNUNET_CONTAINER_DLL_insert(plugin->probe_head, plugin->probe_tail, + tcp_probe_ctx); + tcp_probe_ctx->transmit_handle = GNUNET_CONNECTION_notify_transmit_ready ( + sock, ntohs (tcp_probe_ctx->message.header.size), + GNUNET_TIME_UNIT_FOREVER_REL, ¬ify_send_probe, tcp_probe_ctx); } - /** * Function obtain the network type for a session * @@ -2530,14 +2332,12 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_ATS_Network_Type -tcp_get_network (void *cls, - struct Session *session) +tcp_get_network (void *cls, struct Session *session) { - GNUNET_assert (NULL != session); + GNUNET_assert(NULL != session); return session->ats_address_network_type; } - /** * Entry point for the plugin. * @@ -2547,14 +2347,12 @@ tcp_get_network (void *cls, void * libgnunet_plugin_transport_tcp_init (void *cls) { - static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { - {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, - sizeof (struct WelcomeMessage)}, - {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, - sizeof (struct TCP_NAT_ProbeMessage)}, - {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, - {NULL, NULL, 0, 0} - }; + static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { { + &handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, + sizeof(struct WelcomeMessage) }, { &handle_tcp_nat_probe, NULL, + GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, + sizeof(struct TCP_NAT_ProbeMessage) }, { &handle_tcp_data, NULL, + GNUNET_MESSAGE_TYPE_ALL, 0 }, { NULL, NULL, 0, 0 } }; struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct Plugin *plugin; @@ -2569,11 +2367,10 @@ libgnunet_plugin_transport_tcp_init (void *cls) struct sockaddr **addrs; socklen_t *addrlens; - if (NULL == env->receive) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ + initialze the plugin or the API */ api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &tcp_plugin_address_pretty_printer; @@ -2582,26 +2379,24 @@ libgnunet_plugin_transport_tcp_init (void *cls) return api; } - GNUNET_assert (NULL != env->cfg); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", - "MAX_CONNECTIONS", - &max_connections)) + GNUNET_assert(NULL != env->cfg); + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", + "MAX_CONNECTIONS", &max_connections)) max_connections = 128; aport = 0; - if ((GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT", - &bport)) || (bport > 65535) || - ((GNUNET_OK == - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", - "ADVERTISED-PORT", &aport)) && - (aport > 65535))) - { - LOG (GNUNET_ERROR_TYPE_ERROR, - _("Require valid port number for service `%s' in configuration!\n"), - "transport-tcp"); - return NULL; + if ((GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", + "PORT", &bport)) || (bport > 65535) + || ((GNUNET_OK + == GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", + "ADVERTISED-PORT", &aport)) && (aport > 65535))) + { + LOG(GNUNET_ERROR_TYPE_ERROR, + _("Require valid port number for service `%s' in configuration!\n"), + "transport-tcp"); + return NULL ; } if (aport == 0) aport = bport; @@ -2609,12 +2404,12 @@ 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 @@ -2624,42 +2419,42 @@ libgnunet_plugin_transport_tcp_init (void *cls) myoptions = 0; plugin = GNUNET_new (struct Plugin); - plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); + plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, + GNUNET_YES); plugin->max_connections = max_connections; plugin->cur_connections = 0; plugin->open_port = bport; plugin->adv_port = aport; plugin->env = env; plugin->lsock = NULL; - if ((service != NULL) && - (GNUNET_SYSERR != - (ret_s = - GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, - &addrlens)))) - { - for (ret = ret_s-1; ret >= 0; ret--) - LOG (GNUNET_ERROR_TYPE_INFO, - "Binding to address `%s'\n", - GNUNET_a2s (addrs[ret], addrlens[ret])); - plugin->nat = - GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s, - (const struct sockaddr **) addrs, addrlens, - &tcp_nat_port_map_callback, - &try_connection_reversal, plugin); - for (ret = ret_s -1; ret >= 0; ret--) - { - GNUNET_assert (addrs[ret] != NULL); - GNUNET_free (addrs[ret]); - } - GNUNET_free_non_null (addrs); - GNUNET_free_non_null (addrlens); - } - else - { - plugin->nat = GNUNET_NAT_register (plugin->env->cfg, - GNUNET_YES, 0, 0, NULL, NULL, NULL, - &try_connection_reversal, plugin); - } + if ((service != NULL )&& + (GNUNET_SYSERR != + (ret_s = + GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, + &addrlens)))){ + for (ret = ret_s-1; ret >= 0; ret--) + LOG (GNUNET_ERROR_TYPE_INFO, + "Binding to address `%s'\n", + GNUNET_a2s (addrs[ret], addrlens[ret])); + plugin->nat = + GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s, + (const struct sockaddr **) addrs, addrlens, + &tcp_nat_port_map_callback, + &try_connection_reversal, plugin); + for (ret = ret_s -1; ret >= 0; ret--) + { + GNUNET_assert (addrs[ret] != NULL); + GNUNET_free (addrs[ret]); + } + GNUNET_free_non_null (addrs); + GNUNET_free_non_null (addrlens); +} +else +{ + plugin->nat = GNUNET_NAT_register (plugin->env->cfg, + GNUNET_YES, 0, 0, NULL, NULL, NULL, + &try_connection_reversal, plugin); +} api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = plugin; api->send = &tcp_plugin_send; @@ -2681,51 +2476,48 @@ libgnunet_plugin_transport_tcp_init (void *cls) } else { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", - "TIMEOUT", &idle_timeout)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", + "TIMEOUT", &idle_timeout)) { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "transport-tcp", "TIMEOUT"); - if (plugin->nat != NULL) + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "transport-tcp", + "TIMEOUT"); + if (plugin->nat != NULL ) GNUNET_NAT_unregister (plugin->nat); - GNUNET_free (plugin); - GNUNET_free (api); - return NULL; + GNUNET_free(plugin); + 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)); + memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); for (i = 0; - i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler); - i++) + i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); + i++) plugin->handlers[i].callback_cls = plugin; GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); - plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); + plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, + GNUNET_YES); if (bport != 0) - LOG (GNUNET_ERROR_TYPE_INFO, - _("TCP transport listening on port %llu\n"), bport); + LOG(GNUNET_ERROR_TYPE_INFO, _("TCP transport listening on port %llu\n"), + bport); else - LOG (GNUNET_ERROR_TYPE_INFO, - _("TCP transport not listening on any port (client only)\n")); + LOG(GNUNET_ERROR_TYPE_INFO, + _("TCP transport not listening on any port (client only)\n")); if (aport != bport) - LOG (GNUNET_ERROR_TYPE_INFO, - _("TCP transport advertises itself as being on port %llu\n"), - aport); + LOG(GNUNET_ERROR_TYPE_INFO, + _("TCP transport advertises itself as being on port %llu\n"), aport); /* Initially set connections to 0 */ - GNUNET_assert (NULL != plugin->env->stats); + GNUNET_assert(NULL != plugin->env->stats); GNUNET_STATISTICS_set (plugin->env->stats, - gettext_noop ("# TCP sessions active"), 0, - GNUNET_NO); + gettext_noop ("# TCP sessions active"), 0, GNUNET_NO); return api; } - /** * Exit point from the plugin. * @@ -2743,50 +2535,49 @@ libgnunet_plugin_transport_tcp_done (void *cls) if (NULL == plugin) { - GNUNET_free (api); - return NULL; + GNUNET_free(api); + return NULL ; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down TCP plugin\n"); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); /* Removing leftover sessions */ GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, - &session_disconnect_it, plugin); + &session_disconnect_it, plugin); /* Removing leftover NAT sessions */ GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, - &session_disconnect_it, plugin); + &session_disconnect_it, plugin); next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) { 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); 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_free(cur); + GNUNET_break(0); } - if (plugin->service != NULL) + if (plugin->service != NULL ) GNUNET_SERVICE_stop (plugin->service); else GNUNET_SERVER_destroy (plugin->server); - GNUNET_free (plugin->handlers); - if (plugin->nat != NULL) + GNUNET_free(plugin->handlers); + if (plugin->nat != NULL ) GNUNET_NAT_unregister (plugin->nat); while (NULL != (tcp_probe = plugin->probe_head)) { - GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, - tcp_probe); + GNUNET_CONTAINER_DLL_remove(plugin->probe_head, plugin->probe_tail, + tcp_probe); GNUNET_CONNECTION_destroy (tcp_probe->sock); - GNUNET_free (tcp_probe); + GNUNET_free(tcp_probe); } GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); - GNUNET_free (plugin); - GNUNET_free (api); - return NULL; + GNUNET_free(plugin); + GNUNET_free(api); + return NULL ; } /* end of plugin_transport_tcp.c */ diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index d3a8d1017..836cf2ad5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet - (C) 2010-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) 2010-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. + */ /** * @file transport/plugin_transport_udp.c @@ -44,8 +44,6 @@ #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) -#define PLUGIN_NAME "udp" - /** * Number of messages we can defragment in parallel. We only really * defragment 1 message at a time, but if messages get re-ordered, we @@ -127,7 +125,6 @@ struct PrettyPrinterContext uint32_t options; }; - enum UDP_MessageType { UNDEFINED = 0, @@ -138,7 +135,6 @@ enum UDP_MessageType MSG_BEACON = 5 }; - struct Session { /** @@ -157,11 +153,6 @@ struct Session struct UDP_FragmentationContext *frag_ctx; /** - * Address of the other peer - */ - const struct sockaddr *sock_addr; - - /** * Desired delay for next sending we send to other peer */ struct GNUNET_TIME_Relative flow_delay_for_other_peer; @@ -188,10 +179,7 @@ struct Session struct GNUNET_ATS_Information ats; - /** - * Number of bytes in @e sock_addr. - */ - size_t addrlen; + struct GNUNET_HELLO_Address *address; /** * Reference counter to indicate that this session is @@ -208,22 +196,17 @@ struct Session * @e rc is non-zero). */ int in_destroy; - - int inbound; }; - /** * Closure for #session_cmp_it(). */ struct SessionCompareContext { struct Session *res; - const struct GNUNET_HELLO_Address *addr; - int inbound; + const struct GNUNET_HELLO_Address *address; }; - /** * Closure for #process_inbound_tokenized_messages(). */ @@ -251,7 +234,6 @@ struct SourceInformation }; - /** * Closure for #find_receive_context(). */ @@ -276,8 +258,6 @@ struct FindReceiveContext }; - - /** * Data structure to track defragmentation contexts based * on the source of the UDP traffic. @@ -312,8 +292,6 @@ struct DefragContext size_t addr_len; }; - - /** * Context to send fragmented messages */ @@ -373,7 +351,6 @@ struct UDP_FragmentationContext }; - struct UDP_MessageWrapper { /** @@ -437,7 +414,6 @@ struct UDP_MessageWrapper struct UDP_FragmentationContext *frag_ctx; }; - /** * UDP ACK Message-Packet header (after defragmentation). */ @@ -465,13 +441,11 @@ struct UDP_ACK_Message */ static uint32_t myoptions; - /** * Encapsulation of all of the state of the plugin. */ struct Plugin * plugin; - /** * We have been notified that our readset has something to read. We don't * know which socket needs to be read, so we have to check each one @@ -483,7 +457,6 @@ struct Plugin * plugin; static void udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - /** * We have been notified that our readset has something to read. We don't * know which socket needs to be read, so we have to check each one @@ -495,7 +468,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); static void udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - /** * (re)schedule select tasks for this plugin. * @@ -514,40 +486,41 @@ schedule_select (struct Plugin *plugin) min_delay = GNUNET_TIME_UNIT_FOREVER_REL; for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) min_delay = GNUNET_TIME_relative_min (min_delay, - GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); + GNUNET_TIME_absolute_get_remaining ( + udpw->session->flow_delay_from_other_peer)); - if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel(plugin->select_task); + if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) + GNUNET_SCHEDULER_cancel (plugin->select_task); /* Schedule with: * - write active set if message is ready * - timeout minimum delay */ - plugin->select_task = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, - plugin->rs_v4, - (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, - &udp_plugin_select, plugin); + plugin->select_task = GNUNET_SCHEDULER_add_select ( + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + (0 == min_delay.rel_value_us) ? + GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v4, + (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, + &udp_plugin_select, plugin); } if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) { min_delay = GNUNET_TIME_UNIT_FOREVER_REL; for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) min_delay = GNUNET_TIME_relative_min (min_delay, - GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); + GNUNET_TIME_absolute_get_remaining ( + udpw->session->flow_delay_from_other_peer)); if (GNUNET_SCHEDULER_NO_TASK != plugin->select_task_v6) - GNUNET_SCHEDULER_cancel(plugin->select_task_v6); - plugin->select_task_v6 = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, - plugin->rs_v6, - (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, - &udp_plugin_select_v6, plugin); + GNUNET_SCHEDULER_cancel (plugin->select_task_v6); + plugin->select_task_v6 = GNUNET_SCHEDULER_add_select ( + GNUNET_SCHEDULER_PRIORITY_DEFAULT, + (0 == min_delay.rel_value_us) ? + GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v6, + (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, + &udp_plugin_select_v6, plugin); } } - /** * Function called for a quick conversion of the binary address to * a numeric address. Note that the caller must not free the @@ -573,37 +546,36 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) uint16_t port; uint32_t options; - if ((NULL != addr) && (addrlen == sizeof (struct IPv6UdpAddress))) + if ((NULL != addr) && (addrlen == sizeof(struct IPv6UdpAddress))) { t6 = addr; af = AF_INET6; options = ntohl (t6->options); port = ntohs (t6->u6_port); - memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); + memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); sb = &a6; } - else if ((NULL != addr) && (addrlen == sizeof (struct IPv4UdpAddress))) + else if ((NULL != addr) && (addrlen == sizeof(struct IPv4UdpAddress))) { t4 = addr; af = AF_INET; options = ntohl (t4->options); port = ntohs (t4->u4_port); - memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); + memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); sb = &a4; } else { - return NULL; + return NULL ; } inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); - GNUNET_snprintf (rbuf, sizeof (rbuf), - (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", - PLUGIN_NAME, options, buf, port); + GNUNET_snprintf (rbuf, sizeof(rbuf), + (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, + buf, port); return rbuf; } - /** * Function called to convert a string address to * a binary address. @@ -633,87 +605,85 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, if ((NULL == addr) || (addrlen == 0)) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } if ('\0' != addr[addrlen - 1]) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } if (strlen (addr) != addrlen - 1) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } plugin = GNUNET_strdup (addr); optionstr = strchr (plugin, '.'); if (NULL == optionstr) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } optionstr[0] = '\0'; - optionstr ++; + optionstr++; options = atol (optionstr); address = strchr (optionstr, '.'); if (NULL == address) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } address[0] = '\0'; - address ++; + address++; - if (GNUNET_OK != - GNUNET_STRINGS_to_address_ip (address, strlen (address), - &socket_address)) + if (GNUNET_OK + != GNUNET_STRINGS_to_address_ip (address, strlen (address), + &socket_address)) { - GNUNET_break (0); - GNUNET_free (plugin); + GNUNET_break(0); + GNUNET_free(plugin); return GNUNET_SYSERR; } - GNUNET_free (plugin); + GNUNET_free(plugin); switch (socket_address.ss_family) { case AF_INET: - { - struct IPv4UdpAddress *u4; - struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; - u4 = GNUNET_new (struct IPv4UdpAddress); - u4->options = htonl (options); - u4->ipv4_addr = in4->sin_addr.s_addr; - u4->u4_port = in4->sin_port; - *buf = u4; - *added = sizeof (struct IPv4UdpAddress); - return GNUNET_OK; - } + { + struct IPv4UdpAddress *u4; + struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; + u4 = GNUNET_new (struct IPv4UdpAddress); + u4->options = htonl (options); + u4->ipv4_addr = in4->sin_addr.s_addr; + u4->u4_port = in4->sin_port; + *buf = u4; + *added = sizeof(struct IPv4UdpAddress); + return GNUNET_OK; + } case AF_INET6: - { - struct IPv6UdpAddress *u6; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; - u6 = GNUNET_new (struct IPv6UdpAddress); - u6->options = htonl (options); - u6->ipv6_addr = in6->sin6_addr; - u6->u6_port = in6->sin6_port; - *buf = u6; - *added = sizeof (struct IPv6UdpAddress); - return GNUNET_OK; - } + { + struct IPv6UdpAddress *u6; + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; + u6 = GNUNET_new (struct IPv6UdpAddress); + u6->options = htonl (options); + u6->ipv6_addr = in6->sin6_addr; + u6->u6_port = in6->sin6_port; + *buf = u6; + *added = sizeof(struct IPv6UdpAddress); + return GNUNET_OK; + } default: - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } } - static void -ppc_cancel_task (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PrettyPrinterContext *ppc = cls; @@ -723,11 +693,10 @@ ppc_cancel_task (void *cls, 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); + GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); + GNUNET_free(ppc); } - /** * Append our port and forward the result. * @@ -741,14 +710,14 @@ append_port (void *cls, const char *hostname) struct PrettyPrinterContext *cur; char *ret; - if (hostname == NULL) + if (hostname == NULL ) { - ppc->asc (ppc->asc_cls, NULL); - GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); + ppc->asc (ppc->asc_cls, NULL ); + GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); GNUNET_SCHEDULER_cancel (ppc->timeout_task); ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; ppc->resolver_handle = NULL; - GNUNET_free (ppc); + GNUNET_free(ppc); return; } for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) @@ -758,30 +727,20 @@ append_port (void *cls, const char *hostname) } if (NULL == cur) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid callback for PPC %p \n", ppc); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); 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); + GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, + ppc->port); ppc->asc (ppc->asc_cls, ret); - GNUNET_free (ret); + GNUNET_free(ret); } - /** * Convert the transports address to a nice, human-readable * format. @@ -798,11 +757,9 @@ append_port (void *cls, const char *hostname) */ static void udp_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) + 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; @@ -814,25 +771,25 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, uint16_t port; uint32_t options; - if (addrlen == sizeof (struct IPv6UdpAddress)) + if (addrlen == sizeof(struct IPv6UdpAddress)) { u6 = addr; - memset (&a6, 0, sizeof (a6)); + memset (&a6, 0, sizeof(a6)); a6.sin6_family = AF_INET6; #if HAVE_SOCKADDR_IN_SIN_LEN a6.sin6_len = sizeof (a6); #endif a6.sin6_port = u6->u6_port; - memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); + memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); port = ntohs (u6->u6_port); options = ntohl (u6->options); sb = &a6; - sbs = sizeof (a6); + sbs = sizeof(a6); } - else if (addrlen == sizeof (struct IPv4UdpAddress)) + else if (addrlen == sizeof(struct IPv4UdpAddress)) { u4 = addr; - memset (&a4, 0, sizeof (a4)); + memset (&a4, 0, sizeof(a4)); a4.sin_family = AF_INET; #if HAVE_SOCKADDR_IN_SIN_LEN a4.sin_len = sizeof (a4); @@ -842,13 +799,13 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, port = ntohs (u4->u4_port); options = ntohl (u4->options); sb = &a4; - sbs = sizeof (a4); + sbs = sizeof(a4); } else { /* invalid address */ - GNUNET_break_op (0); - asc (asc_cls, NULL); + GNUNET_break_op(0); + asc (asc_cls, NULL ); return; } ppc = GNUNET_new (struct PrettyPrinterContext); @@ -856,26 +813,23 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, ppc->asc_cls = asc_cls; ppc->port = port; ppc->options = options; - if (addrlen == sizeof (struct IPv6UdpAddress)) + if (addrlen == sizeof(struct IPv6UdpAddress)) 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); + 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); } - static void call_continuation (struct UDP_MessageWrapper *udpw, int result) { size_t overhead; - LOG (GNUNET_ERROR_TYPE_DEBUG, + LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling continuation for %u byte message to `%s' with result %s\n", udpw->payload_size, GNUNET_i2s (&udpw->session->target), (GNUNET_OK == result) ? "OK" : "SYSERR"); @@ -885,160 +839,148 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) else overhead = udpw->msg_size; - switch (result) { - case GNUNET_OK: - switch (udpw->msg_type) { - case MSG_UNFRAGMENTED: - if (NULL != udpw->cont) - { - /* Transport continuation */ - udpw->cont (udpw->cont_cls, &udpw->session->target, result, - udpw->payload_size, udpw->msg_size); - } - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, messages, sent, success", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes payload, sent, success", - udpw->payload_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes overhead, sent, success", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes overhead, sent", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes payload, sent", - udpw->payload_size, GNUNET_NO); - break; - case MSG_FRAGMENTED_COMPLETE: - GNUNET_assert (NULL != udpw->frag_ctx); - if (udpw->frag_ctx->cont != NULL) - udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_OK, - udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, sent, success", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, success", - udpw->payload_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes overhead, sent, success", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes overhead, sent", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes payload, sent", - udpw->payload_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, pending", - -1, GNUNET_NO); - break; - case MSG_FRAGMENTED: - /* Fragmented message: enqueue next fragment */ - if (NULL != udpw->cont) - udpw->cont (udpw->cont_cls, &udpw->session->target, result, - udpw->payload_size, udpw->msg_size); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, fragments, sent, success", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, fragments bytes, sent, success", - udpw->msg_size, GNUNET_NO); - break; - case MSG_ACK: - /* No continuation */ - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, ACK msgs, messages, sent, success", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, ACK msgs, bytes overhead, sent, success", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes overhead, sent", - overhead, GNUNET_NO); - break; - case MSG_BEACON: - GNUNET_break (0); - break; - default: - LOG (GNUNET_ERROR_TYPE_ERROR, - "ERROR: %u\n", udpw->msg_type); - GNUNET_break (0); - break; + switch (result) + { + case GNUNET_OK: + switch (udpw->msg_type) + { + case MSG_UNFRAGMENTED: + if (NULL != udpw->cont) + { + /* Transport continuation */ + udpw->cont (udpw->cont_cls, &udpw->session->target, result, + udpw->payload_size, udpw->msg_size); } + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, messages, sent, success", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, bytes payload, sent, success", + udpw->payload_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, bytes overhead, sent, success", overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); break; - case GNUNET_SYSERR: - switch (udpw->msg_type) { - case MSG_UNFRAGMENTED: - /* Unfragmented message: failed to send */ - if (NULL != udpw->cont) - udpw->cont (udpw->cont_cls, &udpw->session->target, result, - udpw->payload_size, overhead); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, messages, sent, failure", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes payload, sent, failure", - udpw->payload_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes overhead, sent, failure", - overhead, GNUNET_NO); - break; - case MSG_FRAGMENTED_COMPLETE: - GNUNET_assert (NULL != udpw->frag_ctx); - if (udpw->frag_ctx->cont != NULL) - udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_SYSERR, - udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, sent, failure", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - udpw->payload_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, sent, failure", - overhead, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, pending", - -1, GNUNET_NO); - break; - case MSG_FRAGMENTED: - GNUNET_assert (NULL != udpw->frag_ctx); - /* Fragmented message: failed to send */ - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, fragments, sent, failure", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, fragments bytes, sent, failure", - udpw->msg_size, GNUNET_NO); - break; - case MSG_ACK: - /* ACK message: failed to send */ - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, ACK msgs, messages, sent, failure", - 1, GNUNET_NO); - break; - case MSG_BEACON: - /* Beacon message: failed to send */ - GNUNET_break (0); - break; - default: - GNUNET_break (0); - break; - } + case MSG_FRAGMENTED_COMPLETE: + GNUNET_assert(NULL != udpw->frag_ctx); + if (udpw->frag_ctx->cont != NULL ) + udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, + GNUNET_OK, udpw->frag_ctx->payload_size, + udpw->frag_ctx->on_wire_size); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, sent, success", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, success", + udpw->payload_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes overhead, sent, success", overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); + break; + case MSG_FRAGMENTED: + /* Fragmented message: enqueue next fragment */ + if (NULL != udpw->cont) + udpw->cont (udpw->cont_cls, &udpw->session->target, result, + udpw->payload_size, udpw->msg_size); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments, sent, success", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments bytes, sent, success", + udpw->msg_size, GNUNET_NO); + break; + case MSG_ACK: + /* No continuation */ + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK msgs, bytes overhead, sent, success", overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); + break; + case MSG_BEACON: + GNUNET_break(0); break; default: - GNUNET_break (0); + LOG(GNUNET_ERROR_TYPE_ERROR, "ERROR: %u\n", udpw->msg_type); + GNUNET_break(0); break; + } + break; + case GNUNET_SYSERR: + switch (udpw->msg_type) + { + case MSG_UNFRAGMENTED: + /* Unfragmented message: failed to send */ + if (NULL != udpw->cont) + udpw->cont (udpw->cont_cls, &udpw->session->target, result, + udpw->payload_size, overhead); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, messages, sent, failure", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, bytes payload, sent, failure", + udpw->payload_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, + GNUNET_NO); + break; + case MSG_FRAGMENTED_COMPLETE: + GNUNET_assert(NULL != udpw->frag_ctx); + if (udpw->frag_ctx->cont != NULL ) + udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, + GNUNET_SYSERR, udpw->frag_ctx->payload_size, + udpw->frag_ctx->on_wire_size); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, sent, failure", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", + udpw->payload_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); + break; + case MSG_FRAGMENTED: + GNUNET_assert(NULL != udpw->frag_ctx); + /* Fragmented message: failed to send */ + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments, sent, failure", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, fragments bytes, sent, failure", + udpw->msg_size, GNUNET_NO); + break; + case MSG_ACK: + /* ACK message: failed to send */ + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); + break; + case MSG_BEACON: + /* Beacon message: failed to send */ + GNUNET_break(0); + break; + default: + GNUNET_break(0); + break; + } + break; + default: + GNUNET_break(0); + break; } } - /** * Check if the given port is plausible (must be either our listen * port or our advertised port). If it is neither, we return @@ -1056,7 +998,6 @@ check_port (struct Plugin *plugin, uint16_t in_port) return GNUNET_SYSERR; } - /** * Function that will be called to check if a binary address for this * plugin is well-formed and corresponds to an address for THIS peer @@ -1074,28 +1015,26 @@ check_port (struct Plugin *plugin, uint16_t in_port) * */ static int -udp_plugin_check_address (void *cls, - const void *addr, - size_t addrlen) +udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) { struct Plugin *plugin = cls; struct IPv4UdpAddress *v4; struct IPv6UdpAddress *v6; - if ((addrlen != sizeof (struct IPv4UdpAddress)) && - (addrlen != sizeof (struct IPv6UdpAddress))) + if ((addrlen != sizeof(struct IPv4UdpAddress)) + && (addrlen != sizeof(struct IPv6UdpAddress))) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } - if (addrlen == sizeof (struct IPv4UdpAddress)) + if (addrlen == sizeof(struct IPv4UdpAddress)) { v4 = (struct IPv4UdpAddress *) addr; if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) return GNUNET_SYSERR; - if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, - sizeof (struct in_addr))) + if (GNUNET_OK + != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, + sizeof(struct in_addr))) return GNUNET_SYSERR; } else @@ -1103,20 +1042,19 @@ udp_plugin_check_address (void *cls, v6 = (struct IPv6UdpAddress *) addr; if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return GNUNET_SYSERR; } if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) return GNUNET_SYSERR; - if (GNUNET_OK != - GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, - sizeof (struct in6_addr))) + if (GNUNET_OK + != GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, + sizeof(struct in6_addr))) return GNUNET_SYSERR; } return GNUNET_OK; } - /** * Function to free last resources associated with a session. * @@ -1127,39 +1065,35 @@ free_session (struct Session *s) { if (NULL != s->frag_ctx) { - GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); - GNUNET_free (s->frag_ctx); + GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL ); + GNUNET_free(s->frag_ctx); s->frag_ctx = NULL; } - GNUNET_free (s); + GNUNET_free(s); } - static void -dequeue (struct Plugin *plugin, - struct UDP_MessageWrapper * udpw) +dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) { if (plugin->bytes_in_buffer < udpw->msg_size) - GNUNET_break (0); + GNUNET_break(0); else { GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes in buffers", - - (long long) udpw->msg_size, GNUNET_NO); + "# UDP, total, bytes in buffers", -(long long) udpw->msg_size, + GNUNET_NO); plugin->bytes_in_buffer -= udpw->msg_size; } - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, msgs in buffers", - -1, GNUNET_NO); - if (udpw->session->addrlen == sizeof (struct sockaddr_in)) - GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, - plugin->ipv4_queue_tail, udpw); - if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) - GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, - plugin->ipv6_queue_tail, udpw); + GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", + -1, GNUNET_NO); + if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) + GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, + plugin->ipv4_queue_tail, udpw); + if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) + GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, + plugin->ipv6_queue_tail, udpw); } - static void fragmented_message_done (struct UDP_FragmentationContext *fc, int result) { @@ -1168,13 +1102,12 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) struct UDP_MessageWrapper dummy; struct Session *s = fc->session; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "%p : Fragmented message removed with result %s\n", - fc, - (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "%p : Fragmented message removed with result %s\n", fc, + (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); /* Call continuation for fragmented message */ - memset (&dummy, 0, sizeof (dummy)); + memset (&dummy, 0, sizeof(dummy)); dummy.msg_type = MSG_FRAGMENTED_COMPLETE; dummy.msg_size = s->frag_ctx->on_wire_size; dummy.payload_size = s->frag_ctx->payload_size; @@ -1186,46 +1119,43 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) call_continuation (&dummy, result); /* Remove leftover fragments from queue */ - if (s->addrlen == sizeof (struct sockaddr_in6)) + if (s->address->address_length == sizeof(struct sockaddr_in6)) { udpw = plugin->ipv6_queue_head; while (NULL != udpw) { tmp = udpw->next; - if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx)) - { - dequeue (plugin, udpw); - call_continuation (udpw, GNUNET_SYSERR); - GNUNET_free (udpw); - } + if ((udpw->frag_ctx != NULL )&& (udpw->frag_ctx == s->frag_ctx)){ + dequeue (plugin, udpw); + call_continuation (udpw, GNUNET_SYSERR); + GNUNET_free (udpw); + } udpw = tmp; } } - if (s->addrlen == sizeof (struct sockaddr_in)) + if (s->address->address_length == sizeof(struct sockaddr_in)) { udpw = plugin->ipv4_queue_head; - while (udpw!= NULL) + while (udpw != NULL ) { tmp = udpw->next; if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == s->frag_ctx)) { dequeue (plugin, udpw); call_continuation (udpw, GNUNET_SYSERR); - GNUNET_free (udpw); + GNUNET_free(udpw); } udpw = tmp; } } /* Destroy fragmentation context */ - GNUNET_FRAGMENT_context_destroy (fc->frag, - &s->last_expected_msg_delay, - &s->last_expected_ack_delay); + GNUNET_FRAGMENT_context_destroy (fc->frag, &s->last_expected_msg_delay, + &s->last_expected_ack_delay); s->frag_ctx = NULL; - GNUNET_free (fc); + GNUNET_free(fc); } - /** * Functions with this signature are called whenever we need * to close a session due to a disconnect or failure to @@ -1236,19 +1166,16 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) * @return #GNUNET_OK on success */ static int -udp_disconnect_session (void *cls, - struct Session *s) +udp_disconnect_session (void *cls, struct Session *s) { struct Plugin *plugin = cls; struct UDP_MessageWrapper *udpw; struct UDP_MessageWrapper *next; - GNUNET_assert (GNUNET_YES != s->in_destroy); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Session %p to peer `%s' address ended\n", - s, - GNUNET_i2s (&s->target), - GNUNET_a2s (s->sock_addr, s->addrlen)); + GNUNET_assert(GNUNET_YES != s->in_destroy); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' address ended\n", s, + GNUNET_i2s (&s->target), + GNUNET_a2s (s->address->address, s->address->address_length)); /* stop timeout task */ if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) { @@ -1269,7 +1196,7 @@ udp_disconnect_session (void *cls, { dequeue (plugin, udpw); call_continuation (udpw, GNUNET_SYSERR); - GNUNET_free (udpw); + GNUNET_free(udpw); } } next = plugin->ipv6_queue_head; @@ -1280,7 +1207,7 @@ udp_disconnect_session (void *cls, { dequeue (plugin, udpw); call_continuation (udpw, GNUNET_SYSERR); - GNUNET_free (udpw); + GNUNET_free(udpw); } } plugin->env->session_end (plugin->env->cls, &s->target, s); @@ -1290,29 +1217,27 @@ udp_disconnect_session (void *cls, if (NULL != s->frag_ctx->cont) { s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, - s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); - LOG (GNUNET_ERROR_TYPE_DEBUG, + s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Calling continuation for fragemented message to `%s' with result SYSERR\n", GNUNET_i2s (&s->target)); } } - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, - &s->target, - s)); - GNUNET_STATISTICS_set (plugin->env->stats, - "# UDP, sessions active", - GNUNET_CONTAINER_multipeermap_size(plugin->sessions), - GNUNET_NO); + GNUNET_assert( + GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); + GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", + GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); if (s->rc > 0) s->in_destroy = GNUNET_YES; else + { + GNUNET_HELLO_address_free (s->address); free_session (s); + } return GNUNET_OK; } - /** * Function that is called to get the keepalive factor. * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to @@ -1327,7 +1252,6 @@ udp_query_keepalive_factor (void *cls) return 15; } - /** * Destroy a session, plugin is being unloaded. * @@ -1337,9 +1261,8 @@ udp_query_keepalive_factor (void *cls) * @return #GNUNET_OK (continue to iterate) */ static int -disconnect_and_free_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, + void *value) { struct Plugin *plugin = cls; @@ -1347,7 +1270,6 @@ disconnect_and_free_it (void *cls, return GNUNET_OK; } - /** * Disconnect from a remote node. Clean up session if we have one for * this peer. @@ -1357,20 +1279,17 @@ disconnect_and_free_it (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -udp_disconnect (void *cls, - const struct GNUNET_PeerIdentity *target) +udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Disconnecting from peer `%s'\n", - GNUNET_i2s (target)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer `%s'\n", + GNUNET_i2s (target)); /* Clean up sessions */ GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, - &disconnect_and_free_it, plugin); + &disconnect_and_free_it, plugin); } - /** * Session was idle, so disconnect it * @@ -1378,23 +1297,18 @@ udp_disconnect (void *cls, * @param tc scheduler context */ static void -session_timeout (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Session *s = cls; s->timeout_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Session %p was idle for %s, disconnecting\n", - s, - GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, - GNUNET_YES)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Session %p was idle for %s, disconnecting\n", s, + GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, GNUNET_YES)); /* call session destroy function */ - udp_disconnect_session (s->plugin, - s); + udp_disconnect_session (s->plugin, s); } - /** * Increment session timeout due to activity * @@ -1405,155 +1319,51 @@ reschedule_session_timeout (struct Session *s) { if (GNUNET_YES == s->in_destroy) return; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); + GNUNET_assert(GNUNET_SCHEDULER_NO_TASK != s->timeout_task); GNUNET_SCHEDULER_cancel (s->timeout_task); s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, - &session_timeout, - s); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timeout restarted for session %p\n", - s); + &session_timeout, s); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Timeout restarted for session %p\n", s); } - static struct Session * create_session (struct Plugin *plugin, - const struct GNUNET_PeerIdentity *target, - const void *addr, size_t addrlen, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) + const struct GNUNET_HELLO_Address *address) { struct Session *s; - const struct IPv4UdpAddress *t4; - const struct IPv6UdpAddress *t6; - struct sockaddr_in *v4; - struct sockaddr_in6 *v6; - size_t len; - - if (NULL == addr) - { - GNUNET_break (0); - return NULL; - } - switch (addrlen) - { - case sizeof (struct IPv4UdpAddress): - if (NULL == plugin->sockv4) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", - GNUNET_i2s(target), - udp_address_to_string (NULL, addr, addrlen)); - return NULL; - } - t4 = addr; - s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); - s->plugin = plugin; - len = sizeof (struct sockaddr_in); - v4 = (struct sockaddr_in *) &s[1]; - v4->sin_family = AF_INET; -#if HAVE_SOCKADDR_IN_SIN_LEN - v4->sin_len = sizeof (struct sockaddr_in); -#endif - v4->sin_port = t4->u4_port; - v4->sin_addr.s_addr = t4->ipv4_addr; - s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v4, sizeof (struct sockaddr_in)); - break; - case sizeof (struct IPv6UdpAddress): - if (NULL == plugin->sockv6) - { - LOG (GNUNET_ERROR_TYPE_INFO, - "Could not create session for peer `%s' address `%s': IPv6 is not enabled\n", - GNUNET_i2s(target), - udp_address_to_string(NULL, addr, addrlen)); - return NULL; - } - t6 = addr; - s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); - s->plugin = plugin; - len = sizeof (struct sockaddr_in6); - v6 = (struct sockaddr_in6 *) &s[1]; - v6->sin6_family = AF_INET6; -#if HAVE_SOCKADDR_IN_SIN_LEN - v6->sin6_len = sizeof (struct sockaddr_in6); -#endif - v6->sin6_port = t6->u6_port; - v6->sin6_addr = t6->ipv6_addr; - s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v6, sizeof (struct sockaddr_in6)); - break; - default: - /* Must have a valid address to send to */ - GNUNET_STATISTICS_update (plugin->env->stats, - gettext_noop - ("# requests to create session with invalid address"), - 1, GNUNET_NO); - return NULL; - } - s->addrlen = len; - s->target = *target; - s->sock_addr = (const struct sockaddr *) &s[1]; - s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); + s = GNUNET_new (struct Session); + s->address = GNUNET_HELLO_address_copy (address); + s->target = address->peer; + s->last_expected_ack_delay = GNUNET_TIME_relative_multiply ( + GNUNET_TIME_UNIT_MILLISECONDS, 250); s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; - s->inbound = GNUNET_NO; - s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, - &session_timeout, - s); + s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, + &session_timeout, s); return s; } - static int -session_cmp_it (void *cls, - const struct GNUNET_PeerIdentity * key, - void *value) +session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct SessionCompareContext * cctx = cls; - const struct GNUNET_HELLO_Address *address = cctx->addr; + const struct GNUNET_HELLO_Address *address = cctx->address; struct Session *s = value; - socklen_t s_addrlen = s->addrlen; - - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Comparing address %s <-> %s\n", - udp_address_to_string (NULL, (void *) address->address, - address->address_length), - GNUNET_a2s (s->sock_addr, s->addrlen)); - if (s->inbound != cctx->inbound) - return GNUNET_YES; - if ((address->address_length == sizeof (struct IPv4UdpAddress)) && - (s_addrlen == sizeof (struct sockaddr_in))) - { - struct IPv4UdpAddress * u4 = NULL; - u4 = (struct IPv4UdpAddress *) address->address; - GNUNET_assert (NULL != u4); - const struct sockaddr_in *s4 = (const struct sockaddr_in *) s->sock_addr; - if ((0 == memcmp ((const void *) &u4->ipv4_addr,(const void *) &s4->sin_addr, sizeof (struct in_addr))) && - (u4->u4_port == s4->sin_port)) - { - cctx->res = s; - return GNUNET_NO; - } - } - if ((address->address_length == sizeof (struct IPv6UdpAddress)) && - (s_addrlen == sizeof (struct sockaddr_in6))) + LOG(GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n", + udp_address_to_string (NULL, (void *) address->address, address->address_length), + udp_address_to_string (NULL, s->address->address, s->address->address_length)); + + if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) { - struct IPv6UdpAddress * u6 = NULL; - u6 = (struct IPv6UdpAddress *) address->address; - GNUNET_assert (NULL != u6); - const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) s->sock_addr; - if ((0 == memcmp (&u6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr))) && - (u6->u6_port == s6->sin6_port)) - { - cctx->res = s; - return GNUNET_NO; - } + cctx->res = s; + return GNUNET_NO; } return GNUNET_YES; } - /** * Function obtain the network type for a session * @@ -1562,13 +1372,11 @@ session_cmp_it (void *cls, * @return the network type */ static enum GNUNET_ATS_Network_Type -udp_get_network (void *cls, - struct Session *session) +udp_get_network (void *cls, struct Session *session) { return ntohl (session->ats.value); } - /** * Creates a new outbound session the transport service will use to * send data to the peer @@ -1580,107 +1388,130 @@ udp_get_network (void *cls, */ static struct Session * udp_plugin_lookup_session (void *cls, - const struct GNUNET_HELLO_Address *address, - int inbound) + const struct GNUNET_HELLO_Address *address) { struct Plugin * plugin = cls; struct IPv6UdpAddress * udp_a6; struct IPv4UdpAddress * udp_a4; - GNUNET_assert (plugin != NULL); - GNUNET_assert (address != NULL); - - - if ((address->address == NULL) || - ((address->address_length != sizeof (struct IPv4UdpAddress)) && - (address->address_length != sizeof (struct IPv6UdpAddress)))) - { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), - address->address_length, - sizeof (struct IPv4UdpAddress), - sizeof (struct IPv6UdpAddress)); - return NULL; - } + GNUNET_assert(plugin != NULL); + GNUNET_assert(address != NULL); + + if ((address->address == NULL )|| + ((address->address_length != sizeof (struct IPv4UdpAddress)) && + (address->address_length != sizeof (struct IPv6UdpAddress)))){ + LOG (GNUNET_ERROR_TYPE_WARNING, + _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), + address->address_length, + sizeof (struct IPv4UdpAddress), + sizeof (struct IPv6UdpAddress)); + return NULL; +} - if (address->address_length == sizeof (struct IPv4UdpAddress)) + if (address->address_length == sizeof(struct IPv4UdpAddress)) { - if (plugin->sockv4 == NULL) - return NULL; + if (plugin->sockv4 == NULL ) + return NULL ; udp_a4 = (struct IPv4UdpAddress *) address->address; if (udp_a4->u4_port == 0) - return NULL; + return NULL ; } - if (address->address_length == sizeof (struct IPv6UdpAddress)) + if (address->address_length == sizeof(struct IPv6UdpAddress)) { - if (plugin->sockv6 == NULL) - return NULL; + if (plugin->sockv6 == NULL ) + return NULL ; udp_a6 = (struct IPv6UdpAddress *) address->address; if (udp_a6->u6_port == 0) - return NULL; + return NULL ; } /* check if session already exists */ struct SessionCompareContext cctx; - cctx.addr = address; + cctx.address = address; cctx.res = NULL; - cctx.inbound = inbound; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Looking for existing session for peer `%s' `%s' \n", - GNUNET_i2s (&address->peer), - udp_address_to_string(NULL, address->address, address->address_length)); - GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, &address->peer, session_cmp_it, &cctx); - if (cctx.res != NULL) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); + LOG(GNUNET_ERROR_TYPE_ERROR, + "Looking for existing session for peer `%s' `%s' \n", + GNUNET_i2s (&address->peer), + udp_address_to_string(NULL, address->address, address->address_length)); + GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, &address->peer, + session_cmp_it, &cctx); + if (cctx.res != NULL ) + { + LOG(GNUNET_ERROR_TYPE_ERROR, "Found existing session %p\n", cctx.res); return cctx.res; } - return NULL; + return NULL ; } +static int +udp_address_is_inbound (const struct GNUNET_HELLO_Address *address) +{ + if (GNUNET_HELLO_ADDRESS_INFO_INBOUND == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + return GNUNET_YES; + else + return GNUNET_NO; +} static struct Session * udp_plugin_create_session (void *cls, - const struct GNUNET_HELLO_Address *address, - int inbound) + const struct GNUNET_HELLO_Address *address) { struct Session *s; + struct IPv4UdpAddress *udp_v4; + struct IPv6UdpAddress *udp_v6; + + s = create_session (plugin, address); + if (sizeof (struct IPv4UdpAddress) == address->address_length) + { + struct sockaddr_in v4; + udp_v4 = (struct IPv4UdpAddress *) address->address; + memset (&v4, '\0', sizeof (v4)); + v4.sin_family = AF_INET; +#if HAVE_SOCKADDR_IN_SIN_LEN + v4->sin_len = sizeof (struct sockaddr_in); +#endif + v4.sin_port = udp_v4->u4_port; + v4.sin_addr.s_addr = udp_v4->ipv4_addr; + s->ats = plugin->env->get_address_type (plugin->env->cls, + (const struct sockaddr *) &v4, sizeof (v4)); + } + else if (sizeof (struct IPv6UdpAddress) == address->address_length) + { + struct sockaddr_in6 v6; + udp_v6 = (struct IPv6UdpAddress *) address->address; + memset (&v6, '\0', sizeof (v6)); + v6.sin6_family = AF_INET6; +#if HAVE_SOCKADDR_IN_SIN_LEN + v6->sin_len = sizeof (struct sockaddr_in6); +#endif + v6.sin6_port = udp_v6->u6_port; + v6.sin6_addr = udp_v6->ipv6_addr; + s->ats = plugin->env->get_address_type (plugin->env->cls, + (const struct sockaddr *) &v6, sizeof (v6)); + } - s = create_session (plugin, - &address->peer, - address->address, - address->address_length, - NULL, NULL); if (NULL == s) - return NULL; /* protocol not supported or address invalid */ - s->inbound = inbound; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Creating new %s session %p for peer `%s' address `%s'\n", - (GNUNET_YES == s->inbound) ? "inbound" : "outbound", - s, - GNUNET_i2s(&address->peer), - udp_address_to_string(NULL,address->address,address->address_length)); - GNUNET_assert (GNUNET_OK == - GNUNET_CONTAINER_multipeermap_put (plugin->sessions, - &s->target, - s, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); - GNUNET_STATISTICS_set(plugin->env->stats, - "# UDP, sessions active", - GNUNET_CONTAINER_multipeermap_size(plugin->sessions), - GNUNET_NO); + return NULL ; /* protocol not supported or address invalid */ + LOG(GNUNET_ERROR_TYPE_ERROR, + "Creating new %s session %p for peer `%s' address `%s'\n", + (GNUNET_YES == udp_address_is_inbound(address)) ? "inbound" : "outbound", + s, GNUNET_i2s (&address->peer), + udp_address_to_string(NULL,address->address,address->address_length)); + GNUNET_assert( + GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", + GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); return s; } static void udp_plugin_update_session_timeout (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct Session *session) + const struct GNUNET_PeerIdentity *peer, struct Session *session) { if (GNUNET_YES - != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, - peer, session)) + != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, peer, + session)) { GNUNET_break(0); return; @@ -1699,52 +1530,46 @@ udp_plugin_update_session_timeout (void *cls, * @return the session or NULL of max connections exceeded */ static struct Session * -udp_plugin_get_session (void *cls, - const struct GNUNET_HELLO_Address *address) +udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) { struct Session *s; if (NULL == address) { - GNUNET_break (0); - return NULL; + GNUNET_break(0); + return NULL ; } - if ((address->address_length != sizeof (struct IPv4UdpAddress)) && - (address->address_length != sizeof (struct IPv6UdpAddress))) - return NULL; + if ((address->address_length != sizeof(struct IPv4UdpAddress)) + && (address->address_length != sizeof(struct IPv6UdpAddress))) + return NULL ; /* otherwise create new */ - if (NULL != (s = udp_plugin_lookup_session (cls, address, GNUNET_NO))) + if (NULL != (s = udp_plugin_lookup_session (cls, address))) return s; - return udp_plugin_create_session (cls, address, GNUNET_NO); + return udp_plugin_create_session (cls, address); } - static void enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) { if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) - GNUNET_break (0); + GNUNET_break(0); else { GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes in buffers", - udpw->msg_size, GNUNET_NO); + "# UDP, total, bytes in buffers", udpw->msg_size, GNUNET_NO); plugin->bytes_in_buffer += udpw->msg_size; } - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, msgs in buffers", - 1, GNUNET_NO); - if (udpw->session->addrlen == sizeof (struct sockaddr_in)) - GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, - plugin->ipv4_queue_tail, udpw); - if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) - GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, - plugin->ipv6_queue_tail, udpw); + GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", + 1, GNUNET_NO); + if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) + GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, + plugin->ipv4_queue_tail, udpw); + if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) + GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, + plugin->ipv6_queue_tail, udpw); } - - /** * Fragment message was transmitted via UDP, let fragmentation know * to send the next fragment now. @@ -1756,16 +1581,14 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) * @param physical bytes physical sent */ static void -send_next_fragment (void *cls, - const struct GNUNET_PeerIdentity *target, - int result, size_t payload, size_t physical) +send_next_fragment (void *cls, const struct GNUNET_PeerIdentity *target, + int result, size_t payload, size_t physical) { struct UDP_MessageWrapper *udpw = cls; GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); } - /** * Function that is called with messages created by the fragmentation * module. In the case of the 'proc' callback of the @@ -1783,9 +1606,8 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) struct UDP_MessageWrapper * udpw; size_t msg_len = ntohs (msg->size); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Enqueuing fragment with %u bytes\n", msg_len); - frag_ctx->fragments_used ++; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); + frag_ctx->fragments_used++; udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); udpw->session = frag_ctx->session; udpw->msg_buf = (char *) &udpw[1]; @@ -1801,7 +1623,6 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) schedule_select (plugin); } - /** * Function that can be used by the transport service to transmit * a message using the plugin. Note that in the case of a @@ -1830,42 +1651,38 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) * and does NOT mean that the message was not transmitted (DV) */ static ssize_t -udp_plugin_send (void *cls, - struct Session *s, - const char *msgbuf, size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) +udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, + size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct Plugin *plugin = cls; - size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); + size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); struct UDP_FragmentationContext * frag_ctx; struct UDP_MessageWrapper * udpw; struct UDPMessage *udp; char mbuf[udpmlen]; - GNUNET_assert (plugin != NULL); - GNUNET_assert (s != NULL); + GNUNET_assert(plugin != NULL); + GNUNET_assert(s != NULL); - if ((s->addrlen == sizeof (struct sockaddr_in6)) && (plugin->sockv6 == NULL)) + if ((s->address->address_length == sizeof(struct sockaddr_in6)) && (plugin->sockv6 == NULL )) return GNUNET_SYSERR; - if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL)) + if ((s->address->address_length == sizeof(struct sockaddr_in)) && (plugin->sockv4 == NULL )) return GNUNET_SYSERR; if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } - if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, &s->target, s)) + if (GNUNET_YES + != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, + &s->target, s)) { - GNUNET_break (0); + GNUNET_break(0); return GNUNET_SYSERR; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmits %u-byte message to `%s' using address `%s'\n", - udpmlen, - GNUNET_i2s (&s->target), - GNUNET_a2s(s->sock_addr, s->addrlen)); - + LOG(GNUNET_ERROR_TYPE_DEBUG, + "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, + GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); /* Message */ udp = (struct UDPMessage *) mbuf; @@ -1889,26 +1706,25 @@ udp_plugin_send (void *cls, udpw->msg_buf = (char *) &udpw[1]; udpw->msg_size = udpmlen; /* message size with UDP overhead */ udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ - udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); + udpw->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); udpw->cont = cont; udpw->cont_cls = cont_cls; udpw->frag_ctx = NULL; udpw->msg_type = MSG_UNFRAGMENTED; - memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); - memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], msgbuf, msgbuf_size); + memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); + memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], msgbuf, msgbuf_size); enqueue (plugin, udpw); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, messages, attempt", - 1, GNUNET_NO); + "# UDP, unfragmented msgs, messages, attempt", 1, GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes payload, attempt", - udpw->payload_size, GNUNET_NO); + "# UDP, unfragmented msgs, bytes payload, attempt", udpw->payload_size, + GNUNET_NO); } else { /* fragmented message */ - if (s->frag_ctx != NULL) + if (s->frag_ctx != NULL ) return GNUNET_SYSERR; memcpy (&udp[1], msgbuf, msgbuf_size); frag_ctx = GNUNET_new (struct UDP_FragmentationContext); @@ -1916,93 +1732,87 @@ udp_plugin_send (void *cls, frag_ctx->session = s; frag_ctx->cont = cont; frag_ctx->cont_cls = cont_cls; - frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); + frag_ctx->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), + to); frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, - UDP_MTU, - &plugin->tracker, - s->last_expected_msg_delay, - s->last_expected_ack_delay, - &udp->header, - &enqueue_fragment, - frag_ctx); + UDP_MTU, &plugin->tracker, s->last_expected_msg_delay, + s->last_expected_ack_delay, &udp->header, &enqueue_fragment, frag_ctx); s->frag_ctx = frag_ctx; GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, pending", - 1, GNUNET_NO); + "# UDP, fragmented msgs, messages, pending", 1, GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, attempt", - 1, GNUNET_NO); + "# UDP, fragmented msgs, messages, attempt", 1, GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes payload, attempt", - frag_ctx->payload_size, GNUNET_NO); + "# UDP, fragmented msgs, bytes payload, attempt", + frag_ctx->payload_size, GNUNET_NO); } schedule_select (plugin); return udpmlen; } - /** * Our external IP address/port mapping has changed. * * @param cls closure, the 'struct LocalAddrList' * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean * the previous (now invalid) one - * @param addr either the previous or the new public IP address + * @param address either the previous or the new public IP address * @param addrlen actual lenght of the address */ static void udp_nat_port_map_callback (void *cls, int add_remove, - const struct sockaddr *addr, socklen_t addrlen) + const struct sockaddr *addr, socklen_t addrlen) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; struct IPv4UdpAddress u4; struct IPv6UdpAddress u6; void *arg; size_t args; - LOG (GNUNET_ERROR_TYPE_INFO, - "NAT notification to %s address `%s'\n", - (GNUNET_YES == add_remove) ? "add" : "remove", - GNUNET_a2s (addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_INFO, "NAT notification to %s address `%s'\n", + (GNUNET_YES == add_remove) ? "add" : "remove", + GNUNET_a2s (addr, addrlen)); - /* convert 'addr' to our internal format */ + /* convert 'address' to our internal format */ switch (addr->sa_family) { case AF_INET: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); - memset (&u4, 0, sizeof (u4)); - u4.options = htonl(myoptions); + GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); + memset (&u4, 0, sizeof(u4)); + u4.options = htonl (myoptions); u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; if (0 == ((struct sockaddr_in *) addr)->sin_port) - return; + return; arg = &u4; - args = sizeof (struct IPv4UdpAddress); + args = sizeof(struct IPv4UdpAddress); break; case AF_INET6: - GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); - memset (&u4, 0, sizeof (u4)); - u6.options = htonl(myoptions); + GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); + memset (&u4, 0, sizeof(u4)); + u6.options = htonl (myoptions); if (0 == ((struct sockaddr_in6 *) addr)->sin6_port) - return; + return; memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, - sizeof (struct in6_addr)); + sizeof(struct in6_addr)); u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; arg = &u6; - args = sizeof (struct IPv6UdpAddress); + args = sizeof(struct IPv6UdpAddress); break; default: - GNUNET_break (0); + GNUNET_break(0); return; } /* modify our published address list */ - plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "udp"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, add_remove, address); + GNUNET_HELLO_address_free (address); } - - /** * Message tokenizer has broken up an incomming message. Pass it on * to the service. @@ -2014,37 +1824,26 @@ udp_nat_port_map_callback (void *cls, int add_remove, */ static int process_inbound_tokenized_messages (void *cls, void *client, - const struct GNUNET_MessageHeader *hdr) + const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; struct SourceInformation *si = client; struct GNUNET_TIME_Relative delay; - GNUNET_assert (si->session != NULL); + GNUNET_assert(si->session != NULL); if (GNUNET_YES == si->session->in_destroy) return GNUNET_OK; /* setup ATS */ - GNUNET_break (ntohl(si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); + GNUNET_break(ntohl (si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); reschedule_session_timeout (si->session); - delay = plugin->env->receive (plugin->env->cls, - &si->sender, - hdr, - si->session, - (GNUNET_YES == si->session->inbound) - ? NULL : si->arg, - (GNUNET_YES == si->session->inbound) - ? 0 : si->args); + delay = plugin->env->receive (plugin->env->cls, si->session->address, si->session, hdr); plugin->env->update_address_metrics (plugin->env->cls, - &si->sender, - (GNUNET_YES == si->session->inbound) ? NULL : si->arg, - (GNUNET_YES == si->session->inbound) ? 0 : si->args, - si->session, - &si->session->ats, 1); + si->session->address, si->session, + &si->session->ats, 1); si->session->flow_delay_for_other_peer = delay; return GNUNET_OK; } - /** * We've received a UDP Message. Process it (pass contents to main service). * @@ -2055,11 +1854,11 @@ process_inbound_tokenized_messages (void *cls, void *client, */ static void process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, - const struct sockaddr *sender_addr, - socklen_t sender_addr_len) + const struct sockaddr *sender_addr, socklen_t sender_addr_len) { struct SourceInformation si; struct Session * s; + struct GNUNET_HELLO_Address *address; struct IPv4UdpAddress u4; struct IPv6UdpAddress u6; const void *arg; @@ -2067,13 +1866,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, if (0 != ntohl (msg->reserved)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } - if (ntohs (msg->header.size) < - sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) + if (ntohs (msg->header.size) + < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } @@ -2081,40 +1880,40 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, switch (sender_addr->sa_family) { case AF_INET: - GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); - memset (&u4, 0, sizeof (u4)); + GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in)); + memset (&u4, 0, sizeof(u4)); u6.options = htonl (0); u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; arg = &u4; - args = sizeof (u4); + args = sizeof(u4); break; case AF_INET6: - GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); - memset (&u6, 0, sizeof (u6)); + GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in6)); + memset (&u6, 0, sizeof(u6)); u6.options = htonl (0); u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; arg = &u6; - args = sizeof (u6); + args = sizeof(u6); break; default: - GNUNET_break (0); + GNUNET_break(0); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Received message with %u bytes from peer `%s' at `%s'\n", - (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), - GNUNET_a2s (sender_addr, sender_addr_len)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Received message with %u bytes from peer `%s' at `%s'\n", + (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), + GNUNET_a2s (sender_addr, sender_addr_len)); - struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args); - if (NULL == (s = udp_plugin_lookup_session (plugin, address, GNUNET_YES))) + address = GNUNET_HELLO_address_allocate ( &msg->sender, PLUGIN_NAME, + arg, args, GNUNET_HELLO_ADDRESS_INFO_INBOUND); + if (NULL == (s = udp_plugin_lookup_session (plugin, address))) { - s = udp_plugin_create_session (plugin, address, GNUNET_YES); - plugin->env->session_start (NULL, &address->peer, PLUGIN_NAME, - address->address, address->address_length, s, NULL, 0); + s = udp_plugin_create_session (plugin, address); + plugin->env->session_start (NULL, address, s, NULL, 0); } - GNUNET_free (address); + GNUNET_free(address); /* iterate over all embedded messages */ si.session = s; @@ -2122,18 +1921,14 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, si.arg = arg; si.args = args; s->rc++; - GNUNET_SERVER_mst_receive (plugin->mst, - &si, - (const char *) &msg[1], - ntohs (msg->header.size) - sizeof (struct UDPMessage), - GNUNET_YES, - GNUNET_NO); + GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1], + ntohs (msg->header.size) - sizeof(struct UDPMessage), GNUNET_YES, + GNUNET_NO); s->rc--; - if ( (0 == s->rc) && (GNUNET_YES == s->in_destroy)) + if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) free_session (s); } - /** * Scan the heap for a receive context with the given address. * @@ -2146,13 +1941,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, */ static int find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, - void *element, GNUNET_CONTAINER_HeapCostType cost) + void *element, GNUNET_CONTAINER_HeapCostType cost) { struct FindReceiveContext *frc = cls; struct DefragContext *e = element; - if ((frc->addr_len == e->addr_len) && - (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) + if ((frc->addr_len == e->addr_len) + && (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) { frc->rc = e; return GNUNET_NO; @@ -2160,7 +1955,6 @@ find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, return GNUNET_YES; } - /** * Process a defragmented message. * @@ -2174,35 +1968,30 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) { - GNUNET_break (0); + GNUNET_break(0); return; } - if (ntohs (msg->size) < sizeof (struct UDPMessage)) + if (ntohs (msg->size) < sizeof(struct UDPMessage)) { - GNUNET_break (0); + GNUNET_break(0); return; } process_udp_message (rc->plugin, (const struct UDPMessage *) msg, - rc->src_addr, rc->addr_len); + rc->src_addr, rc->addr_len); } - struct LookupContext { struct Session *res; - const struct sockaddr * addr; - - size_t addrlen; + const struct GNUNET_HELLO_Address *address; int must_have_frag_ctx; }; - static int -lookup_session_by_addr_it (void *cls, - const struct GNUNET_PeerIdentity *key, - void *value) +lookup_session_by_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, + void *value) { struct LookupContext *l_ctx = cls; struct Session * s = value; @@ -2210,15 +1999,7 @@ lookup_session_by_addr_it (void *cls, if ((GNUNET_YES == l_ctx->must_have_frag_ctx) && (NULL == s->frag_ctx)) return GNUNET_YES; - /* - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Comparing session: have %s %s %p<-> want %s\n", - GNUNET_a2s(s->sock_addr, s->addrlen), - (GNUNET_YES == s->inbound) ? "inbound" : "outbound", - s->frag_ctx, - GNUNET_a2s(l_ctx->addr, l_ctx->addrlen)); - */ - if ((s->addrlen == l_ctx->addrlen) && - (0 == memcmp (s->sock_addr, l_ctx->addr, s->addrlen))) + if (0 == GNUNET_HELLO_address_cmp (s->address, l_ctx->address)) { l_ctx->res = s; return GNUNET_YES; @@ -2226,7 +2007,6 @@ lookup_session_by_addr_it (void *cls, return GNUNET_YES; } - /** * Transmit an acknowledgement. * @@ -2238,20 +2018,19 @@ static void ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) { struct DefragContext *rc = cls; - size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); + size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); struct UDP_ACK_Message *udp_ack; uint32_t delay = 0; struct UDP_MessageWrapper *udpw; struct Session *s; struct LookupContext l_ctx; - l_ctx.addr = rc->src_addr; - l_ctx.addrlen = rc->addr_len; + l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, rc->src_addr, + rc->addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE); l_ctx.res = NULL; l_ctx.must_have_frag_ctx = GNUNET_NO; GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, - &lookup_session_by_addr_it, - &l_ctx); + &lookup_session_by_addr_it, &l_ctx); s = l_ctx.res; if (NULL == s) @@ -2260,20 +2039,15 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) if (s->flow_delay_for_other_peer.rel_value_us <= UINT32_MAX) delay = s->flow_delay_for_other_peer.rel_value_us; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending ACK to `%s' including delay of %s\n", - GNUNET_a2s (rc->src_addr, - (rc->src_addr->sa_family == - AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct - sockaddr_in6)), - GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, - GNUNET_YES)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %s\n", + GNUNET_a2s (rc->src_addr, (rc->src_addr->sa_family == AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6)), + GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, GNUNET_YES)); udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); udpw->msg_size = msize; udpw->payload_size = 0; udpw->session = s; udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; - udpw->msg_buf = (char *)&udpw[1]; + udpw->msg_buf = (char *) &udpw[1]; udpw->msg_type = MSG_ACK; udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; udp_ack->header.size = htons ((uint16_t) msize); @@ -2284,28 +2058,21 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) enqueue (rc->plugin, udpw); } - static void -read_process_msg (struct Plugin *plugin, - const struct GNUNET_MessageHeader *msg, - const struct sockaddr *addr, - socklen_t fromlen) +read_process_msg (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, + const struct sockaddr *addr, socklen_t fromlen) { - if (ntohs (msg->size) < sizeof (struct UDPMessage)) + if (ntohs (msg->size) < sizeof(struct UDPMessage)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } - process_udp_message (plugin, (const struct UDPMessage *) msg, - addr, fromlen); + process_udp_message (plugin, (const struct UDPMessage *) msg, addr, fromlen); } - static void -read_process_ack (struct Plugin *plugin, - const struct GNUNET_MessageHeader *msg, - const struct sockaddr *addr, - socklen_t fromlen) +read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, + const struct sockaddr *addr, socklen_t fromlen) { const struct GNUNET_MessageHeader *ack; const struct UDP_ACK_Message *udp_ack; @@ -2313,70 +2080,64 @@ read_process_ack (struct Plugin *plugin, struct Session *s; struct GNUNET_TIME_Relative flow_delay; - if (ntohs (msg->size) < - sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) + if (ntohs (msg->size) + < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } udp_ack = (const struct UDP_ACK_Message *) msg; - l_ctx.addr = (const struct sockaddr *) addr; - l_ctx.addrlen = fromlen; + + l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, + (const struct sockaddr *) addr, fromlen, GNUNET_HELLO_ADDRESS_INFO_NONE); l_ctx.res = NULL; l_ctx.must_have_frag_ctx = GNUNET_YES; GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, - &lookup_session_by_addr_it, - &l_ctx); + &lookup_session_by_addr_it, &l_ctx); s = l_ctx.res; if ((NULL == s) || (NULL == s->frag_ctx)) { return; } - flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "We received a sending delay of %s\n", - GNUNET_STRINGS_relative_time_to_string (flow_delay, - GNUNET_YES)); - s->flow_delay_from_other_peer = - GNUNET_TIME_relative_to_absolute (flow_delay); + LOG(GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %s\n", + GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES)); + s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay); ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; - if (ntohs (ack->size) != - ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) + if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } - if (0 != memcmp (&l_ctx.res->target, &udp_ack->sender, sizeof (struct GNUNET_PeerIdentity))) - GNUNET_break (0); + if (0 + != memcmp (&l_ctx.res->target, &udp_ack->sender, + sizeof(struct GNUNET_PeerIdentity))) + GNUNET_break(0); if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", - (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), - GNUNET_a2s (addr, fromlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", + (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), + GNUNET_a2s (addr, fromlen)); /* Expect more ACKs to arrive */ return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Message full ACK'ed\n", - (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), - GNUNET_a2s (addr, fromlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Message full ACK'ed\n", + (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), + GNUNET_a2s (addr, fromlen)); /* Remove fragmented message after successful sending */ fragmented_message_done (s->frag_ctx, GNUNET_OK); } - static void read_process_fragment (struct Plugin *plugin, - const struct GNUNET_MessageHeader *msg, - const struct sockaddr *addr, - socklen_t fromlen) + const struct GNUNET_MessageHeader *msg, const struct sockaddr *addr, + socklen_t fromlen) { struct DefragContext *d_ctx; struct GNUNET_TIME_Absolute now; @@ -2386,17 +2147,15 @@ read_process_fragment (struct Plugin *plugin, frc.addr = addr; frc.addr_len = fromlen; - LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", - (unsigned int) ntohs (msg->size), - GNUNET_a2s (addr, fromlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", + (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); /* Lookup existing receive context for this address */ - GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, - &find_receive_context, - &frc); + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, &find_receive_context, + &frc); now = GNUNET_TIME_absolute_get (); d_ctx = frc.rc; - if (d_ctx == NULL) + if (d_ctx == NULL ) { /* Create a new defragmentation context */ d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen); @@ -2404,46 +2163,39 @@ read_process_fragment (struct Plugin *plugin, d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1]; d_ctx->addr_len = fromlen; d_ctx->plugin = plugin; - d_ctx->defrag = - GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU, - UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, - &fragment_msg_proc, &ack_proc); - d_ctx->hnode = - GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, - (GNUNET_CONTAINER_HeapCostType) - now.abs_value_us); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Created new defragmentation context for %u-byte fragment from `%s'\n", - (unsigned int) ntohs (msg->size), - GNUNET_a2s (addr, fromlen)); + d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, + UDP_MTU, UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, &fragment_msg_proc, + &ack_proc); + d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, + (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Created new defragmentation context for %u-byte fragment from `%s'\n", + (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); } else { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing defragmentation context for %u-byte fragment from `%s'\n", - (unsigned int) ntohs (msg->size), - GNUNET_a2s (addr, fromlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Found existing defragmentation context for %u-byte fragment from `%s'\n", + (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); } if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) { /* keep this 'rc' from expiring */ GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode, - (GNUNET_CONTAINER_HeapCostType) - now.abs_value_us); + (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); } if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > - UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) + UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) { /* remove 'rc' that was inactive the longest */ d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); - GNUNET_assert (NULL != d_ctx); + GNUNET_assert(NULL != d_ctx); GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); - GNUNET_free (d_ctx); + GNUNET_free(d_ctx); } } - /** * Read and process a message from the given socket. * @@ -2459,10 +2211,10 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) ssize_t size; const struct GNUNET_MessageHeader *msg; - fromlen = sizeof (addr); - memset (&addr, 0, sizeof (addr)); - size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), - (struct sockaddr *) &addr, &fromlen); + fromlen = sizeof(addr); + memset (&addr, 0, sizeof(addr)); + size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof(buf), + (struct sockaddr *) &addr, &fromlen); #if MINGW /* On SOCK_DGRAM UDP sockets recvfrom might fail with a * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) @@ -2475,146 +2227,134 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) * Unreachable message. */ if ( (-1 == size) && (ECONNRESET == errno) ) - return; + return; #endif if (-1 == size) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP failed to receive data: %s\n", STRERROR (errno)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP failed to receive data: %s\n", + STRERROR (errno)); /* Connection failure or something. Not a protocol violation. */ return; } - if (size < sizeof (struct GNUNET_MessageHeader)) + if (size < sizeof(struct GNUNET_MessageHeader)) { - LOG (GNUNET_ERROR_TYPE_WARNING, + LOG(GNUNET_ERROR_TYPE_WARNING, "UDP got %u bytes, which is not enough for a GNUnet message header\n", - (unsigned int) size); + (unsigned int ) size); /* _MAY_ be a connection failure (got partial message) */ /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ - GNUNET_break_op (0); + GNUNET_break_op(0); return; } msg = (const struct GNUNET_MessageHeader *) buf; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP received %u-byte message from `%s' type %u\n", - (unsigned int) size, - GNUNET_a2s ((const struct sockaddr *) &addr, fromlen), - ntohs (msg->type)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "UDP received %u-byte message from `%s' type %u\n", (unsigned int ) size, + GNUNET_a2s ((const struct sockaddr * ) &addr, fromlen), + ntohs (msg->type)); if (size != ntohs (msg->size)) { - GNUNET_break_op (0); + GNUNET_break_op(0); return; } - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, received", - size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, bytes, received", + size, GNUNET_NO); switch (ntohs (msg->type)) { case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: if (GNUNET_YES == plugin->enable_broadcasting_receiving) - udp_broadcast_receive (plugin, buf, size, - (const struct sockaddr *) &addr, fromlen); + udp_broadcast_receive (plugin, buf, size, (const struct sockaddr *) &addr, + fromlen); return; case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: - read_process_msg (plugin, msg, - (const struct sockaddr *) &addr, fromlen); + read_process_msg (plugin, msg, (const struct sockaddr *) &addr, fromlen); return; case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: - read_process_ack (plugin, msg, - (const struct sockaddr *) &addr, fromlen); + read_process_ack (plugin, msg, (const struct sockaddr *) &addr, fromlen); return; case GNUNET_MESSAGE_TYPE_FRAGMENT: - read_process_fragment (plugin, msg, - (const struct sockaddr *) &addr, fromlen); + read_process_fragment (plugin, msg, (const struct sockaddr *) &addr, + fromlen); return; default: - GNUNET_break_op (0); + GNUNET_break_op(0); return; } } - static struct UDP_MessageWrapper * remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, - struct GNUNET_NETWORK_Handle *sock) + struct GNUNET_NETWORK_Handle *sock) { struct UDP_MessageWrapper *udpw = NULL; struct GNUNET_TIME_Relative remaining; udpw = head; - while (udpw != NULL) + while (udpw != NULL ) { /* Find messages with timeout */ remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) { /* Message timed out */ - switch (udpw->msg_type) { - case MSG_UNFRAGMENTED: - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, sent, timeout", - udpw->msg_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, messages, sent, timeout", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, messages, sent, timeout", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, unfragmented msgs, bytes, sent, timeout", - udpw->payload_size, GNUNET_NO); - /* Not fragmented message */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Message for peer `%s' with size %u timed out\n", - GNUNET_i2s(&udpw->session->target), udpw->payload_size); - call_continuation (udpw, GNUNET_SYSERR); - /* Remove message */ - dequeue (plugin, udpw); - GNUNET_free (udpw); - break; - case MSG_FRAGMENTED: - /* Fragmented message */ - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, sent, timeout", - udpw->frag_ctx->on_wire_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, messages, sent, timeout", - 1, GNUNET_NO); - call_continuation (udpw, GNUNET_SYSERR); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Fragment for message for peer `%s' with size %u timed out\n", - GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size); - - - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, messages, sent, timeout", - 1, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, fragmented msgs, bytes, sent, timeout", - udpw->frag_ctx->payload_size, GNUNET_NO); - /* Remove fragmented message due to timeout */ - fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); - break; - case MSG_ACK: - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, sent, timeout", - udpw->msg_size, GNUNET_NO); - GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, messages, sent, timeout", - 1, GNUNET_NO); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "ACK Message for peer `%s' with size %u timed out\n", - GNUNET_i2s(&udpw->session->target), udpw->payload_size); - call_continuation (udpw, GNUNET_SYSERR); - dequeue (plugin, udpw); - GNUNET_free (udpw); - break; - default: - break; + switch (udpw->msg_type) + { + case MSG_UNFRAGMENTED: + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, messages, sent, timeout", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, unfragmented msgs, bytes, sent, timeout", + udpw->payload_size, GNUNET_NO); + /* Not fragmented message */ + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Message for peer `%s' with size %u timed out\n", + GNUNET_i2s (&udpw->session->target), udpw->payload_size); + call_continuation (udpw, GNUNET_SYSERR); + /* Remove message */ + dequeue (plugin, udpw); + GNUNET_free(udpw); + break; + case MSG_FRAGMENTED: + /* Fragmented message */ + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes, sent, timeout", udpw->frag_ctx->on_wire_size, + GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); + call_continuation (udpw, GNUNET_SYSERR); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Fragment for message for peer `%s' with size %u timed out\n", + GNUNET_i2s (&udpw->session->target), udpw->frag_ctx->payload_size); + + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, messages, sent, timeout", 1, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, fragmented msgs, bytes, sent, timeout", + udpw->frag_ctx->payload_size, GNUNET_NO); + /* Remove fragmented message due to timeout */ + fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); + break; + case MSG_ACK: + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); + GNUNET_STATISTICS_update (plugin->env->stats, + "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "ACK Message for peer `%s' with size %u timed out\n", + GNUNET_i2s (&udpw->session->target), udpw->payload_size); + call_continuation (udpw, GNUNET_SYSERR); + dequeue (plugin, udpw); + GNUNET_free(udpw); + break; + default: + break; } if (sock == plugin->sockv4) udpw = plugin->ipv4_queue_head; @@ -2622,33 +2362,32 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, udpw = plugin->ipv6_queue_head; else { - GNUNET_break (0); /* should never happen */ + GNUNET_break(0); /* should never happen */ udpw = NULL; } GNUNET_STATISTICS_update (plugin->env->stats, - "# messages dismissed due to timeout", - 1, GNUNET_NO); + "# messages dismissed due to timeout", 1, GNUNET_NO); } else { /* Message did not time out, check flow delay */ - remaining = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer); + remaining = GNUNET_TIME_absolute_get_remaining ( + udpw->session->flow_delay_from_other_peer); if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) { /* this message is not delayed */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Message for peer `%s' (%u bytes) is not delayed \n", - GNUNET_i2s(&udpw->session->target), udpw->payload_size); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Message for peer `%s' (%u bytes) is not delayed \n", + GNUNET_i2s (&udpw->session->target), udpw->payload_size); break; /* Found message to send, break */ } else { /* Message is delayed, try next */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Message for peer `%s' (%u bytes) is delayed for %s\n", - GNUNET_i2s(&udpw->session->target), udpw->payload_size, - GNUNET_STRINGS_relative_time_to_string (remaining, - GNUNET_YES)); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Message for peer `%s' (%u bytes) is delayed for %s\n", + GNUNET_i2s (&udpw->session->target), udpw->payload_size, + GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); udpw = udpw->next; } } @@ -2656,54 +2395,51 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, return udpw; } - static void -analyze_send_error (struct Plugin *plugin, - const struct sockaddr * sa, - socklen_t slen, - int error) +analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, + socklen_t slen, int error) { static int network_down_error; struct GNUNET_ATS_Information type; - type = plugin->env->get_address_type (plugin->env->cls,sa, slen); - if (((GNUNET_ATS_NET_LAN == ntohl(type.value)) || (GNUNET_ATS_NET_WAN == ntohl(type.value))) && - ((ENETUNREACH == errno) || (ENETDOWN == errno))) - { - if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) - { - /* IPv4: "Network unreachable" or "Network down" - * - * This indicates we do not have connectivity - */ - LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _("UDP could not transmit message to `%s': " - "Network seems down, please check your network configuration\n"), - GNUNET_a2s (sa, slen)); - } - if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) - { - /* IPv6: "Network unreachable" or "Network down" - * - * This indicates that this system is IPv6 enabled, but does not - * have a valid global IPv6 address assigned or we do not have - * connectivity - */ - - LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _("UDP could not transmit IPv6 message! " - "Please check your network configuration and disable IPv6 if your " - "connection does not have a global IPv6 address\n")); - } - } - else - { - LOG (GNUNET_ERROR_TYPE_WARNING, - "UDP could not transmit message to `%s': `%s'\n", - GNUNET_a2s (sa, slen), STRERROR (error)); - } -} - + type = plugin->env->get_address_type (plugin->env->cls, sa, slen); + if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) + || (GNUNET_ATS_NET_WAN == ntohl (type.value))) + && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) + { + if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) + { + /* IPv4: "Network unreachable" or "Network down" + * + * This indicates we do not have connectivity + */ + LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _("UDP could not transmit message to `%s': " + "Network seems down, please check your network configuration\n"), + GNUNET_a2s (sa, slen)); + } + if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) + { + /* IPv6: "Network unreachable" or "Network down" + * + * This indicates that this system is IPv6 enabled, but does not + * have a valid global IPv6 address assigned or we do not have + * connectivity + */ + + LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _("UDP could not transmit IPv6 message! " + "Please check your network configuration and disable IPv6 if your " + "connection does not have a global IPv6 address\n")); + } + } + else + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "UDP could not transmit message to `%s': `%s'\n", + GNUNET_a2s (sa, slen), STRERROR (error)); + } + } static size_t udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) @@ -2715,53 +2451,51 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) struct UDP_MessageWrapper *udpw = NULL; /* Find message to send */ - udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) ? plugin->ipv4_queue_head : plugin->ipv6_queue_head, - sock); + udpw = remove_timeout_messages_and_select ( + (sock == plugin->sockv4) ? + plugin->ipv4_queue_head : plugin->ipv6_queue_head, sock); if (NULL == udpw) return 0; /* No message to send */ - sa = udpw->session->sock_addr; - slen = udpw->session->addrlen; + sa = udpw->session->address->address; + slen = udpw->session->address->address_length; - sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, slen); + sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, + slen); if (GNUNET_SYSERR == sent) { /* Failure */ analyze_send_error (plugin, sa, slen, errno); - call_continuation(udpw, GNUNET_SYSERR); + call_continuation (udpw, GNUNET_SYSERR); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, sent, failure", - sent, GNUNET_NO); + "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, messages, sent, failure", - 1, GNUNET_NO); + "# UDP, total, messages, sent, failure", 1, GNUNET_NO); } else { /* Success */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", - (unsigned int) (udpw->msg_size), GNUNET_i2s(&udpw->session->target) ,GNUNET_a2s (sa, slen), (int) sent, - (sent < 0) ? STRERROR (errno) : "ok"); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", + (unsigned int ) (udpw->msg_size), GNUNET_i2s (&udpw->session->target), + GNUNET_a2s (sa, slen), (int ) sent, + (sent < 0) ? STRERROR (errno) : "ok"); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, bytes, sent, success", - sent, GNUNET_NO); + "# UDP, total, bytes, sent, success", sent, GNUNET_NO); GNUNET_STATISTICS_update (plugin->env->stats, - "# UDP, total, messages, sent, success", - 1, GNUNET_NO); + "# UDP, total, messages, sent, success", 1, GNUNET_NO); if (NULL != udpw->frag_ctx) - udpw->frag_ctx->on_wire_size += udpw->msg_size; + udpw->frag_ctx->on_wire_size += udpw->msg_size; call_continuation (udpw, GNUNET_OK); } dequeue (plugin, udpw); - GNUNET_free (udpw); + GNUNET_free(udpw); udpw = NULL; return sent; } - /** * We have been notified that our readset has something to read. We don't * know which socket needs to be read, so we have to check each one @@ -2778,19 +2512,17 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) plugin->select_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && - (NULL != plugin->sockv4) && - (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)) ) + if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) + && (NULL != plugin->sockv4) + && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) udp_select_read (plugin, plugin->sockv4); - if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && - (NULL != plugin->sockv4) && - (NULL != plugin->ipv4_queue_head) && - (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)) ) + if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) + && (NULL != plugin->sockv4) && (NULL != plugin->ipv4_queue_head) + && (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4))) udp_select_send (plugin, plugin->sockv4); schedule_select (plugin); } - /** * We have been notified that our readset has something to read. We don't * know which socket needs to be read, so we have to check each one @@ -2807,26 +2539,23 @@ udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - if ( ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) && - (NULL != plugin->sockv6) && - (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)) ) + if (((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) + && (NULL != plugin->sockv6) + && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) udp_select_read (plugin, plugin->sockv6); - if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && - (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) && - (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) ) - udp_select_send (plugin, plugin->sockv6); + if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) + && (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL )&& + (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) )udp_select_send (plugin, plugin->sockv6); schedule_select (plugin); } - /** * * @return number of sockets that were successfully bound */ static int -setup_sockets (struct Plugin *plugin, - const struct sockaddr_in6 *bind_v6, - const struct sockaddr_in *bind_v4) +setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, + const struct sockaddr_in *bind_v4) { int tries; int sockets_created = 0; @@ -2845,46 +2574,52 @@ setup_sockets (struct Plugin *plugin, plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); if (NULL == plugin->sockv6) { - LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv6 since it is not supported on this system!\n"); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Disabling IPv6 since it is not supported on this system!\n"); plugin->enable_ipv6 = GNUNET_NO; } else { - memset (&server_addrv6, '\0', sizeof (struct sockaddr_in6)); + memset (&server_addrv6, '\0', sizeof(struct sockaddr_in6)); #if HAVE_SOCKADDR_IN_SIN_LEN server_addrv6.sin6_len = sizeof (struct sockaddr_in6); #endif server_addrv6.sin6_family = AF_INET6; if (NULL != bind_v6) - server_addrv6.sin6_addr = bind_v6->sin6_addr; + server_addrv6.sin6_addr = bind_v6->sin6_addr; else - server_addrv6.sin6_addr = in6addr_any; + server_addrv6.sin6_addr = in6addr_any; if (0 == plugin->port) /* autodetect */ - server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); + server_addrv6.sin6_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); else - server_addrv6.sin6_port = htons (plugin->port); - addrlen = sizeof (struct sockaddr_in6); + server_addrv6.sin6_port = htons (plugin->port); + addrlen = sizeof(struct sockaddr_in6); server_addr = (struct sockaddr *) &server_addrv6; tries = 0; while (tries < 10) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", - GNUNET_a2s (server_addr, addrlen)); - /* binding */ - if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, - server_addr, addrlen)) - break; - eno = errno; - if (0 != plugin->port) - { - tries = 10; /* fail */ - break; /* bind failed on specific port */ - } - /* autodetect */ - server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); - tries ++; + LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", + GNUNET_a2s (server_addr, addrlen)); + /* binding */ + if (GNUNET_OK + == GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, + addrlen)) + break; + eno = errno; + if (0 != plugin->port) + { + tries = 10; /* fail */ + break; /* bind failed on specific port */ + } + /* autodetect */ + server_addrv6.sin6_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); + tries++; } if (tries >= 10) { @@ -2893,21 +2628,18 @@ setup_sockets (struct Plugin *plugin, plugin->sockv6 = NULL; } - if (plugin->sockv6 != NULL) + if (plugin->sockv6 != NULL ) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv6 socket created on port %s\n", - GNUNET_a2s (server_addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 socket created on port %s\n", + GNUNET_a2s (server_addr, addrlen)); addrs[sockets_created] = (struct sockaddr *) &server_addrv6; - addrlens[sockets_created] = sizeof (struct sockaddr_in6); + addrlens[sockets_created] = sizeof(struct sockaddr_in6); sockets_created++; } else { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to bind UDP socket to %s: %s\n", - GNUNET_a2s (server_addr, addrlen), - STRERROR (eno)); + LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", + GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); } } } @@ -2917,13 +2649,14 @@ setup_sockets (struct Plugin *plugin, plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); if (NULL == plugin->sockv4) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); - LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv4 since it is not supported on this system!\n"); + GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket"); + LOG(GNUNET_ERROR_TYPE_WARNING, + "Disabling IPv4 since it is not supported on this system!\n"); plugin->enable_ipv4 = GNUNET_NO; } else { - memset (&server_addrv4, '\0', sizeof (struct sockaddr_in)); + memset (&server_addrv4, '\0', sizeof(struct sockaddr_in)); #if HAVE_SOCKADDR_IN_SIN_LEN server_addrv4.sin_len = sizeof (struct sockaddr_in); #endif @@ -2935,34 +2668,37 @@ setup_sockets (struct Plugin *plugin, if (0 == plugin->port) /* autodetect */ - server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); + server_addrv4.sin_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); else server_addrv4.sin_port = htons (plugin->port); - - addrlen = sizeof (struct sockaddr_in); + addrlen = sizeof(struct sockaddr_in); server_addr = (struct sockaddr *) &server_addrv4; tries = 0; while (tries < 10) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", - GNUNET_a2s (server_addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", + GNUNET_a2s (server_addr, addrlen)); /* binding */ - if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, - server_addr, addrlen)) - break; + if (GNUNET_OK + == GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen)) + break; eno = errno; if (0 != plugin->port) { - tries = 10; /* fail */ - break; /* bind failed on specific port */ + tries = 10; /* fail */ + break; /* bind failed on specific port */ } /* autodetect */ - server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); - tries ++; + server_addrv4.sin_port = htons ( + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + + 32000); + tries++; } if (tries >= 10) @@ -2972,40 +2708,39 @@ setup_sockets (struct Plugin *plugin, plugin->sockv4 = NULL; } - if (plugin->sockv4 != NULL) + if (plugin->sockv4 != NULL ) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "IPv4 socket created on port %s\n", GNUNET_a2s (server_addr, addrlen)); + LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv4 socket created on port %s\n", + GNUNET_a2s (server_addr, addrlen)); addrs[sockets_created] = (struct sockaddr *) &server_addrv4; - addrlens[sockets_created] = sizeof (struct sockaddr_in); + addrlens[sockets_created] = sizeof(struct sockaddr_in); sockets_created++; } else { - LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to bind UDP socket to %s: %s\n", - GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); + LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", + GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); } } if (0 == sockets_created) { - LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); - return 0; /* No sockets created, return */ + LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); + return 0; /* No sockets created, return */ } /* Create file descriptors */ if (plugin->enable_ipv4 == GNUNET_YES) { - plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); - plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_zero (plugin->rs_v4); - GNUNET_NETWORK_fdset_zero (plugin->ws_v4); - if (NULL != plugin->sockv4) - { - GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); - GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); - } + plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); + plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); + GNUNET_NETWORK_fdset_zero (plugin->rs_v4); + GNUNET_NETWORK_fdset_zero (plugin->ws_v4); + if (NULL != plugin->sockv4) + { + GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); + GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); + } } if (plugin->enable_ipv6 == GNUNET_YES) @@ -3022,16 +2757,13 @@ setup_sockets (struct Plugin *plugin, } schedule_select (plugin); - plugin->nat = GNUNET_NAT_register (plugin->env->cfg, - GNUNET_NO, plugin->port, - sockets_created, - (const struct sockaddr **) addrs, addrlens, - &udp_nat_port_map_callback, NULL, plugin); + plugin->nat = GNUNET_NAT_register (plugin->env->cfg, GNUNET_NO, plugin->port, + sockets_created, (const struct sockaddr **) addrs, addrlens, + &udp_nat_port_map_callback, NULL, plugin); return sockets_created; } - /** * The exported method. Makes the core api available via a global and * returns the udp transport API. @@ -3064,7 +2796,7 @@ libgnunet_plugin_transport_udp_init (void *cls) if (NULL == env->receive) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully - initialze the plugin or the API */ + initialze the plugin or the API */ api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &udp_plugin_address_pretty_printer; @@ -3073,106 +2805,105 @@ libgnunet_plugin_transport_udp_init (void *cls) return api; } - GNUNET_assert (NULL != env->stats); + GNUNET_assert(NULL != env->stats); /* Get port number: port == 0 : autodetect a port, * > 0 : use this port, not given : 2086 default */ - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", - &port)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", + "PORT", &port)) port = 2086; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", - "ADVERTISED_PORT", &aport)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", + "ADVERTISED_PORT", &aport)) aport = port; if (port > 65535) { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, - 65535); - return NULL; + LOG(GNUNET_ERROR_TYPE_WARNING, + _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, + 65535); + return NULL ; } /* Protocols */ - if ((GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", - "DISABLEV6"))) + if ((GNUNET_YES + == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))) enable_v6 = GNUNET_NO; else enable_v6 = GNUNET_YES; /* Addresses */ have_bind4 = GNUNET_NO; - memset (&server_addrv4, 0, sizeof (server_addrv4)); - if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", - "BINDTO", &bind4_address)) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - bind4_address); + memset (&server_addrv4, 0, sizeof(server_addrv4)); + if (GNUNET_YES + == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", + "BINDTO", &bind4_address)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Binding udp plugin to specific address: `%s'\n", bind4_address); if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) { - GNUNET_free (bind4_address); - return NULL; + GNUNET_free(bind4_address); + return NULL ; } have_bind4 = GNUNET_YES; } - GNUNET_free_non_null (bind4_address); + GNUNET_free_non_null(bind4_address); have_bind6 = GNUNET_NO; - memset (&server_addrv6, 0, sizeof (server_addrv6)); - if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", - "BINDTO6", &bind6_address)) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Binding udp plugin to specific address: `%s'\n", - bind6_address); - if (1 != - inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) + memset (&server_addrv6, 0, sizeof(server_addrv6)); + if (GNUNET_YES + == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", + "BINDTO6", &bind6_address)) + { + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Binding udp plugin to specific address: `%s'\n", bind6_address); + if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) { - LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), - bind6_address); - GNUNET_free (bind6_address); - return NULL; + LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), + bind6_address); + GNUNET_free(bind6_address); + return NULL ; } have_bind6 = GNUNET_YES; } - GNUNET_free_non_null (bind6_address); + GNUNET_free_non_null(bind6_address); /* Initialize my flags */ myoptions = 0; /* Enable neighbour discovery */ - enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", - "BROADCAST"); + enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-udp", "BROADCAST"); if (enable_broadcasting == GNUNET_SYSERR) enable_broadcasting = GNUNET_NO; - enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", - "BROADCAST_RECEIVE"); + enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, + "transport-udp", "BROADCAST_RECEIVE"); if (enable_broadcasting_recv == GNUNET_SYSERR) enable_broadcasting_recv = GNUNET_YES; - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", - "BROADCAST_INTERVAL", &fancy_interval)) + if (GNUNET_SYSERR + == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", + "BROADCAST_INTERVAL", &fancy_interval)) { interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); } else { - if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_relative(fancy_interval, &interval)) - { - interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); - } - GNUNET_free (fancy_interval); + if (GNUNET_SYSERR + == GNUNET_STRINGS_fancy_time_to_relative (fancy_interval, &interval)) + { + interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); + } + GNUNET_free(fancy_interval); } /* Maximum datarate */ - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", - "MAX_BPS", &udp_max_bps)) + if (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", + "MAX_BPS", &udp_max_bps)) { - udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ + udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ } p = GNUNET_new (struct Plugin); @@ -3185,7 +2916,8 @@ libgnunet_plugin_transport_udp_init (void *cls) p->enable_broadcasting_receiving = enable_broadcasting_recv; p->env = env; p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); - p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); + p->defrag_ctxs = GNUNET_CONTAINER_heap_create ( + GNUNET_CONTAINER_HEAP_ORDER_MIN); p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); GNUNET_BANDWIDTH_tracker_init (&p->tracker, GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); @@ -3197,7 +2929,7 @@ libgnunet_plugin_transport_udp_init (void *cls) if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) { LOG (GNUNET_ERROR_TYPE_ERROR, - _("Failed to create network sockets, plugin failed\n")); + _("Failed to create network sockets, plugin failed\n")); GNUNET_CONTAINER_multipeermap_destroy (p->sessions); GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); GNUNET_SERVER_mst_destroy (p->mst); @@ -3225,23 +2957,19 @@ libgnunet_plugin_transport_udp_init (void *cls) return api; } - static int -heap_cleanup_iterator (void *cls, - struct GNUNET_CONTAINER_HeapNode *node, - void *element, - GNUNET_CONTAINER_HeapCostType cost) +heap_cleanup_iterator (void *cls, struct GNUNET_CONTAINER_HeapNode *node, + void *element, GNUNET_CONTAINER_HeapCostType cost) { struct DefragContext * d_ctx = element; GNUNET_CONTAINER_heap_remove_node (node); - GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); - GNUNET_free (d_ctx); + GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); + GNUNET_free(d_ctx); return GNUNET_YES; } - /** * The exported method. Makes the core api available via a global and * returns the udp transport API. @@ -3259,17 +2987,17 @@ libgnunet_plugin_transport_udp_done (void *cls) if (NULL == plugin) { - GNUNET_free (api); - return NULL; + GNUNET_free(api); + return NULL ; } stop_broadcast (plugin); - if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) + if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) { GNUNET_SCHEDULER_cancel (plugin->select_task); plugin->select_task = GNUNET_SCHEDULER_NO_TASK; } - if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK) + if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK ) { GNUNET_SCHEDULER_cancel (plugin->select_task_v6); plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; @@ -3280,7 +3008,7 @@ libgnunet_plugin_transport_udp_done (void *cls) { if (NULL != plugin->sockv4) { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); + GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); plugin->sockv4 = NULL; } GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); @@ -3290,7 +3018,7 @@ libgnunet_plugin_transport_udp_done (void *cls) { if (NULL != plugin->sockv6) { - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); + GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); plugin->sockv6 = NULL; GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); @@ -3304,60 +3032,60 @@ libgnunet_plugin_transport_udp_done (void *cls) } if (NULL != plugin->defrag_ctxs) { - GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, - heap_cleanup_iterator, NULL); + GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, heap_cleanup_iterator, + NULL ); GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); plugin->defrag_ctxs = NULL; } - if (plugin->mst != NULL) + if (plugin->mst != NULL ) { - GNUNET_SERVER_mst_destroy(plugin->mst); + GNUNET_SERVER_mst_destroy (plugin->mst); plugin->mst = NULL; } /* Clean up leftover messages */ struct UDP_MessageWrapper * udpw; udpw = plugin->ipv4_queue_head; - while (udpw != NULL) + while (udpw != NULL ) { struct UDP_MessageWrapper *tmp = udpw->next; dequeue (plugin, udpw); - call_continuation(udpw, GNUNET_SYSERR); - GNUNET_free (udpw); + call_continuation (udpw, GNUNET_SYSERR); + GNUNET_free(udpw); udpw = tmp; } udpw = plugin->ipv6_queue_head; - while (udpw != NULL) + while (udpw != NULL ) { struct UDP_MessageWrapper *tmp = udpw->next; dequeue (plugin, udpw); - call_continuation(udpw, GNUNET_SYSERR); - GNUNET_free (udpw); + call_continuation (udpw, GNUNET_SYSERR); + GNUNET_free(udpw); udpw = tmp; } /* Clean up sessions */ - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Cleaning up sessions\n"); - GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); + 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); next = ppc_dll_head; for (cur = next; NULL != cur; cur = next) { 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_break(0); } plugin->nat = NULL; - GNUNET_free (plugin); - GNUNET_free (api); + GNUNET_free(plugin); + GNUNET_free(api); #if DEBUG_MALLOC struct Allocation *allocation; while (NULL != ahead) @@ -3374,8 +3102,7 @@ libgnunet_plugin_transport_udp_done (void *cls) GNUNET_free (allocator); } #endif - return NULL; + return NULL ; } - /* end of plugin_transport_udp.c */ diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index 8f78ed4bc..1994fa5e2 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h @@ -41,6 +41,8 @@ #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) +#define PLUGIN_NAME "udp" + #define DEBUG_UDP GNUNET_NO #define DEBUG_UDP_BROADCASTING GNUNET_NO diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index c17a3ccff..669ebdb01 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c @@ -135,6 +135,7 @@ broadcast_ipv6_mst_cb (void *cls, void *client, { struct Plugin *plugin = cls; struct Mstv6Context *mc = client; + struct GNUNET_HELLO_Address *address; const struct GNUNET_MessageHeader *hello; const struct UDP_Beacon_Message *msg; struct GNUNET_ATS_Information atsi; @@ -155,19 +156,12 @@ broadcast_ipv6_mst_cb (void *cls, void *client, GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); hello = (struct GNUNET_MessageHeader *) &msg[1]; - plugin->env->receive (plugin->env->cls, - &msg->sender, - hello, - NULL, - (const char *) &mc->addr, - sizeof (mc->addr)); - plugin->env->update_address_metrics (plugin->env->cls, - &msg->sender, - (const char *) &mc->addr, - sizeof (mc->addr), - NULL, - &atsi, 1); - + address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME, + (const char *) &mc->addr, sizeof (mc->addr), GNUNET_HELLO_ADDRESS_INFO_INBOUND); + plugin->env->receive (plugin->env->cls, address, NULL, hello); + plugin->env->update_address_metrics (plugin->env->cls, address, + NULL, &atsi, 1); + GNUNET_HELLO_address_free (address); GNUNET_STATISTICS_update (plugin->env->stats, _ ("# IPv6 multicast HELLO beacons received via udp"), @@ -183,6 +177,7 @@ broadcast_ipv4_mst_cb (void *cls, void *client, { struct Plugin *plugin = cls; struct Mstv4Context *mc = client; + struct GNUNET_HELLO_Address *address; const struct GNUNET_MessageHeader *hello; const struct UDP_Beacon_Message *msg; struct GNUNET_ATS_Information atsi; @@ -204,19 +199,12 @@ broadcast_ipv4_mst_cb (void *cls, void *client, GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); hello = (struct GNUNET_MessageHeader *) &msg[1]; - plugin->env->receive (plugin->env->cls, - &msg->sender, - hello, - NULL, - (const char *) &mc->addr, - sizeof (mc->addr)); - - plugin->env->update_address_metrics (plugin->env->cls, - &msg->sender, - (const char *) &mc->addr, - sizeof (mc->addr), - NULL, - &atsi, 1); + address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME, + (const char *) &mc->addr, sizeof (mc->addr), GNUNET_HELLO_ADDRESS_INFO_INBOUND); + plugin->env->receive (plugin->env->cls, address, NULL, hello); + plugin->env->update_address_metrics (plugin->env->cls, address, + NULL, &atsi, 1); + GNUNET_HELLO_address_free (address); GNUNET_STATISTICS_update (plugin->env->stats, _("# IPv4 broadcast HELLO beacons received via udp"), diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 3a2fa6516..384787ae9 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -103,11 +103,7 @@ struct Session struct Plugin * plugin; - struct UnixAddress *addr; - - size_t addrlen; - - int inbound; + struct GNUNET_HELLO_Address *address; /** * Session timeout task @@ -468,17 +464,9 @@ struct LookupCtx /** * Location to store the session, if found. */ - struct Session *s; - - /** - * Address we are looking for. - */ - const struct UnixAddress *ua; + struct Session *res; - /** - * Number of bytes in @e ua - */ - size_t ua_len; + struct GNUNET_HELLO_Address *address; }; @@ -496,20 +484,13 @@ lookup_session_it (void *cls, void *value) { struct LookupCtx *lctx = cls; - struct Session *t = value; - - if (t->addrlen != lctx->ua_len) - { - GNUNET_break (0); - return GNUNET_YES; - } + struct Session *s = value; - if (0 == memcmp (t->addr, lctx->ua, lctx->ua_len)) + if (0 == GNUNET_HELLO_address_cmp (lctx->address, s->address)) { - lctx->s = t; + lctx->res = s; return GNUNET_NO; } - GNUNET_break (0); return GNUNET_YES; } @@ -525,18 +506,16 @@ lookup_session_it (void *cls, */ static struct Session * lookup_session (struct Plugin *plugin, - const struct GNUNET_PeerIdentity *sender, - const struct UnixAddress *ua, size_t ua_len) + struct GNUNET_HELLO_Address *address) { struct LookupCtx lctx; - lctx.s = NULL; - lctx.ua = ua; - lctx.ua_len = ua_len; + lctx.address = address; + lctx.res = NULL; GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, - sender, + &address->peer, &lookup_session_it, &lctx); - return lctx.s; + return lctx.res; } @@ -561,7 +540,7 @@ unix_session_disconnect (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting session for peer `%s' `%s'\n", GNUNET_i2s (&s->target), - s->addr); + unix_address_to_string (NULL, s->address->address, s->address->address_length) ); plugin->env->session_end (plugin->env->cls, &s->target, s); removed = GNUNET_NO; next = plugin->msg_head; @@ -594,6 +573,7 @@ unix_session_disconnect (void *cls, GNUNET_SCHEDULER_cancel (s->timeout_task); s->timeout_task = GNUNET_SCHEDULER_NO_TASK; } + GNUNET_HELLO_address_free (s->address); GNUNET_free (s); return GNUNET_OK; } @@ -746,12 +726,7 @@ struct GetSessionIteratorContext /** * Address information. */ - const char *address; - - /** - * Number of bytes in @e address - */ - size_t addrlen; + const struct GNUNET_HELLO_Address *address; }; @@ -771,8 +746,7 @@ get_session_it (void *cls, struct GetSessionIteratorContext *gsi = cls; struct Session *s = value; - if ((GNUNET_NO == s->inbound) && (gsi->addrlen == s->addrlen) && - (0 == memcmp (gsi->address, s->addr, s->addrlen)) ) + if (0 == GNUNET_HELLO_address_cmp(s->address, gsi->address)) { gsi->res = s; return GNUNET_NO; @@ -868,27 +842,23 @@ unix_plugin_get_session (void *cls, } /* Check if already existing */ - gsi.address = (const char *) address->address; - gsi.addrlen = address->address_length; + gsi.address = address; gsi.res = NULL; GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, &address->peer, &get_session_it, &gsi); if (NULL != gsi.res) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Found existing session\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; } /* create a new session */ - s = GNUNET_malloc (sizeof (struct Session) + address->address_length); - s->addr = (struct UnixAddress *) &s[1]; - s->addrlen = address->address_length; - s->plugin = plugin; - s->inbound = GNUNET_NO; - memcpy (s->addr, address->address, address->address_length); - memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); + s = GNUNET_new (struct Session); + s->target = address->peer; + s->address = GNUNET_HELLO_address_copy (address); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, @@ -918,7 +888,6 @@ unix_plugin_update_session_timeout (void *cls, &session->target, session)) return; - reschedule_session_timeout (session); } @@ -970,7 +939,8 @@ unix_plugin_send (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session for peer `%s' `%s'\n", GNUNET_i2s (&session->target), - (const char *) session->addr); + unix_address_to_string(NULL, session->address->address, + session->address->address_length)); GNUNET_break (0); return GNUNET_SYSERR; } @@ -978,7 +948,8 @@ unix_plugin_send (void *cls, "Sending %u bytes with session for peer `%s' `%s'\n", msgbuf_size, GNUNET_i2s (&session->target), - (const char *) session->addr); + 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); @@ -1025,7 +996,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, const struct UnixAddress *ua, size_t ua_len) { struct Session *s = NULL; - struct GNUNET_HELLO_Address * addr; + struct GNUNET_HELLO_Address *address; GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); @@ -1037,31 +1008,23 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, ntohs (currhdr->size), GNUNET_NO); - addr = GNUNET_HELLO_address_allocate (sender, - "unix", - ua, - ua_len); - s = lookup_session (plugin, sender, ua, ua_len); + /* Look for existing session */ + address = GNUNET_HELLO_address_allocate (sender, PLUGIN_NAME, ua, ua_len, + GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ + s = lookup_session (plugin, address); + if (NULL == s) { - s = unix_plugin_get_session (plugin, addr); - s->inbound = GNUNET_YES; + s = unix_plugin_get_session (plugin, address); /* Notify transport and ATS about new inbound session */ - plugin->env->session_start (NULL, sender, - PLUGIN_NAME, ua, ua_len, s, &plugin->ats_network, 1); + plugin->env->session_start (NULL, s->address, s, &plugin->ats_network, 1); } + GNUNET_HELLO_address_free (address); reschedule_session_timeout (s); - plugin->env->receive (plugin->env->cls, sender, currhdr, s, - (GNUNET_YES == s->inbound) ? NULL : (const char *) ua, - (GNUNET_YES == s->inbound) ? 0 : ua_len); - - plugin->env->update_address_metrics (plugin->env->cls, sender, - (GNUNET_YES == s->inbound) ? NULL : (const char *) ua, - (GNUNET_YES == s->inbound) ? 0 : ua_len, - s, &plugin->ats_network, 1); - - GNUNET_free (addr); + plugin->env->receive (plugin->env->cls, s->address, s, currhdr); + plugin->env->update_address_metrics (plugin->env->cls, s->address, s, + &plugin->ats_network, 1); } @@ -1193,8 +1156,8 @@ unix_plugin_select_write (struct Plugin *plugin) msgw->msgsize, msgw->priority, msgw->timeout, - msgw->session->addr, - msgw->session->addrlen, + msgw->session->address->address, + msgw->session->address->address_length, msgw->payload, msgw->cont, msgw->cont_cls); @@ -1517,6 +1480,7 @@ address_notification (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; size_t len; struct UnixAddress *ua; @@ -1527,16 +1491,19 @@ address_notification (void *cls, memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; - plugin->env->notify_address (plugin->env->cls, GNUNET_YES, - ua, len, "unix"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE); + + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); GNUNET_free (ua); + GNUNET_free (address); } /** * Increment session timeout due to activity * - * @param s session for which the timeout should be moved + * @param res session for which the timeout should be moved */ static void reschedule_session_timeout (struct Session *s) @@ -1672,6 +1639,7 @@ libgnunet_plugin_transport_unix_done (void *cls) { struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; + struct GNUNET_HELLO_Address *address; struct UNIXMessageWrapper * msgw; struct UnixAddress *ua; size_t len; @@ -1687,10 +1655,13 @@ libgnunet_plugin_transport_unix_done (void *cls) ua->options = htonl (myoptions); ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); - plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - ua, len, "unix"); + GNUNET_free (address); GNUNET_free (ua); + while (NULL != (msgw = plugin->msg_head)) { GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 1fafc4070..1026eb584 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -351,7 +351,9 @@ struct MacEndpoint /** * peer mac address */ - struct WlanAddress addr; + //struct WlanAddress addr; + + struct GNUNET_HELLO_Address *address; /** * Inbound or outbound session @@ -612,8 +614,8 @@ send_ack (void *cls, uint32_t msg_id, get_radiotap_header (endpoint, radio_header, size); get_wlan_header (endpoint->plugin, &radio_header->frame, - &endpoint->addr.mac, - size); + endpoint->address->address, + endpoint->address->address_length); memcpy (&radio_header[1], hdr, msize); if (NULL != GNUNET_HELPER_send (endpoint->plugin->suid_helper, @@ -789,10 +791,11 @@ create_session (struct MacEndpoint *endpoint, GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); LOG (GNUNET_ERROR_TYPE_DEBUG, "Created new %s session %p for peer `%s' with endpoint %s\n", + (GNUNET_YES == inbound) ? "inbound" : "outbound", session, GNUNET_i2s (peer), - mac_to_string (&endpoint->addr.mac)); + mac_to_string (endpoint->address->address)); return session; } @@ -870,8 +873,8 @@ transmit_fragment (void *cls, get_radiotap_header (endpoint, radio_header, size); get_wlan_header (endpoint->plugin, &radio_header->frame, - &endpoint->addr.mac, - size); + endpoint->address->address, + endpoint->address->address_length); memcpy (&radio_header[1], hdr, msize); GNUNET_assert (NULL == fm->sh); fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, @@ -1072,15 +1075,16 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ static struct MacEndpoint * create_macendpoint (struct Plugin *plugin, - const struct WlanAddress *addr) + const struct GNUNET_HELLO_Address *address) { struct MacEndpoint *pos; for (pos = plugin->mac_head; NULL != pos; pos = pos->next) - if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress))) + if (0 == memcmp (address->address, pos->address->address, + pos->address->address_length)) return pos; pos = GNUNET_new (struct MacEndpoint); - pos->addr = *addr; + pos->address = GNUNET_HELLO_address_copy (address); pos->plugin = plugin; pos->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, @@ -1090,8 +1094,7 @@ create_macendpoint (struct Plugin *plugin, &send_ack); pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; - pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - 100); + pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100); pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); pos->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout, @@ -1100,9 +1103,8 @@ create_macendpoint (struct Plugin *plugin, 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, addr, sizeof (struct WlanAddress))); + LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", + wlan_plugin_address_to_string(NULL, address->address, address->address_length)); return pos; } @@ -1149,7 +1151,7 @@ wlan_plugin_get_session (void *cls, "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)); - endpoint = create_macendpoint (plugin, address->address); + endpoint = create_macendpoint (plugin, address); return get_session (endpoint, &address->peer, GNUNET_NO); } @@ -1261,6 +1263,7 @@ static int process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; struct MacAndSession *mas = client; struct MacAndSession xmas; struct GNUNET_ATS_Information ats; @@ -1291,21 +1294,18 @@ 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->addr, sizeof (struct WlanAddress))); + wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, mas->endpoint->address->address_length)); GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO messages received via WLAN"), 1, GNUNET_NO); + plugin->env->receive (plugin->env->cls, - &tmpsource, - hdr, - mas->session, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); + mas->endpoint->address, + mas->session, + hdr); plugin->env->update_address_metrics (plugin->env->cls, - &tmpsource, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), + mas->endpoint->address, mas->session, &ats, 1); break; @@ -1318,7 +1318,8 @@ 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->addr, sizeof (struct WlanAddress))); + wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); GNUNET_STATISTICS_update (plugin->env->stats, _("# fragments received via WLAN"), 1, GNUNET_NO); (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, @@ -1339,7 +1340,8 @@ 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->addr, sizeof (struct WlanAddress)), + wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length), fm); mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); if (NULL != fm->cont) @@ -1354,13 +1356,15 @@ 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->addr, sizeof (struct WlanAddress))); + wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); 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->addr, sizeof (struct WlanAddress))); + wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, + mas->endpoint->address->address_length)); break; case GNUNET_MESSAGE_TYPE_WLAN_DATA: if (NULL == mas->endpoint) @@ -1395,12 +1399,14 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) if (NULL == (xmas.session = lookup_session (mas->endpoint, &wlanheader->sender, GNUNET_YES))) { xmas.session = create_session (mas->endpoint, &wlanheader->sender, GNUNET_YES); - plugin->env->session_start (NULL, &wlanheader->sender, - PLUGIN_NAME, &mas->endpoint->addr, - sizeof (struct WlanAddress), xmas.session, NULL, 0); + address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME, + &mas->endpoint->address, sizeof (struct WlanAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->session_start (NULL, address, xmas.session, NULL, 0); LOG (GNUNET_ERROR_TYPE_DEBUG, "Notifying transport about peer `%s''s new inbound session %p \n", GNUNET_i2s (&wlanheader->sender), xmas.session); + GNUNET_HELLO_address_free (address); } LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing %u bytes of WLAN DATA from peer `%s'\n", @@ -1429,17 +1435,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) (unsigned int) ntohs (hdr->type), GNUNET_i2s (&mas->session->target)); plugin->env->receive (plugin->env->cls, - &mas->session->target, - hdr, - mas->session, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); + mas->session->mac->address, + mas->session, + hdr); plugin->env->update_address_metrics (plugin->env->cls, - &mas->session->target, - (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, - (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), - mas->session, - &ats, 1); + mas->session->mac->address, + mas->session, + &ats, 1); break; } return GNUNET_OK; @@ -1458,6 +1460,7 @@ handle_helper_message (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) { struct Plugin *plugin = cls; + struct GNUNET_HELLO_Address *address; const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; struct WlanAddress wa; @@ -1484,24 +1487,26 @@ handle_helper_message (void *cls, void *client, memset (&wa, 0, sizeof (struct WlanAddress)); wa.mac = plugin->mac_address; wa.options = htonl(plugin->options); - plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - &wa, - sizeof (wa), - "wlan"); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); + GNUNET_HELLO_address_free (address); } plugin->mac_address = cm->mac; plugin->have_mac = GNUNET_YES; + memset (&wa, 0, sizeof (struct WlanAddress)); wa.mac = plugin->mac_address; wa.options = htonl(plugin->options); + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", mac_to_string (&cm->mac), GNUNET_i2s (plugin->env->my_identity)); - plugin->env->notify_address (plugin->env->cls, GNUNET_YES, - &wa, - sizeof (struct WlanAddress), - "wlan"); + plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); + GNUNET_HELLO_address_free (address); break; case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: LOG (GNUNET_ERROR_TYPE_DEBUG, @@ -1551,7 +1556,10 @@ handle_helper_message (void *cls, void *client, mac_to_string (&rxinfo->frame.addr2)); wa.mac = rxinfo->frame.addr2; wa.options = htonl (0); - mas.endpoint = create_macendpoint (plugin, &wa); + address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, &wa, + sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); + mas.endpoint = create_macendpoint (plugin, address); + GNUNET_HELLO_address_free (address); mas.session = NULL; (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer, &mas, @@ -1738,7 +1746,8 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type, void * libgnunet_plugin_transport_wlan_done (void *cls) { - struct WlanAddress wa; + struct WlanAddress wa; + struct GNUNET_HELLO_Address *address; struct GNUNET_TRANSPORT_PluginFunctions *api = cls; struct Plugin *plugin = api->cls; struct MacEndpoint *endpoint; @@ -1752,14 +1761,17 @@ libgnunet_plugin_transport_wlan_done (void *cls) if (GNUNET_YES == plugin->have_mac) { - memset (&wa, 0, sizeof (wa)); - wa.options = htonl (plugin->options); - wa.mac = plugin->mac_address; - plugin->env->notify_address (plugin->env->cls, GNUNET_NO, - &wa, - sizeof (struct WlanAddress), - "wlan"); - plugin->have_mac = GNUNET_NO; + memset (&wa, 0, sizeof(wa)); + wa.options = htonl (plugin->options); + wa.mac = plugin->mac_address; + address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, + PLUGIN_NAME, &wa, sizeof (struct WlanAddress), + GNUNET_HELLO_ADDRESS_INFO_NONE); + + plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); + plugin->have_mac = GNUNET_NO; + + GNUNET_HELLO_address_free (address); } if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 6c81acb49..13920d6fe 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -1,22 +1,22 @@ /* - This file is part of GNUnet. - (C) 2009 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) 2009 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/test_plugin_transport.c * @brief testcase for transport_api.c @@ -120,21 +120,17 @@ unsigned int pretty_printers_running; */ static int ok; - struct AddressWrapper { struct AddressWrapper *next; struct AddressWrapper *prev; - void *addr; - - size_t addrlen; + struct GNUNET_HELLO_Address *address; char *addrstring; }; - static void end () { @@ -144,33 +140,32 @@ end () if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) { - GNUNET_SCHEDULER_cancel (timeout_endbadly); - timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (timeout_endbadly); + timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; } if (NULL != api) - GNUNET_PLUGIN_unload (libname, api); + GNUNET_PLUGIN_unload (libname, api); while (NULL != head) { - w = head; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin did not remove address `%s'\n", w->addrstring); - GNUNET_CONTAINER_DLL_remove (head, tail, w); - c ++; - GNUNET_free (w->addr); - GNUNET_free (w->addrstring); - GNUNET_free (w); + w = head; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", + w->addrstring); + GNUNET_CONTAINER_DLL_remove(head, tail, w); + c++; + GNUNET_HELLO_address_free(w->address); + GNUNET_free(w->addrstring); + GNUNET_free(w); } if (c > 0) { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin did not remove %u addresses \n", c); + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", + c); ok = 1; } - - GNUNET_free (libname); + GNUNET_free(libname); libname = NULL; GNUNET_STATISTICS_destroy (stats, GNUNET_NO); stats = NULL; @@ -182,7 +177,6 @@ end () } } - static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -192,48 +186,49 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) { - GNUNET_SCHEDULER_cancel (timeout_wait); - timeout_wait = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; } if (pretty_printers_running > 0) { - timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &end_badly, &ok); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Have pending calls to pretty_printer ... deferring shutdown\n"); - return; + timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &end_badly, &ok); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, + "Have pending calls to pretty_printer ... deferring shutdown\n"); + return; } if (NULL != cls) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Test took too long to execute, timeout .... \n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Test took too long to execute, timeout .... \n"); } if (NULL != libname) { if (NULL != api) GNUNET_PLUGIN_unload (libname, api); - GNUNET_free (libname); + GNUNET_free(libname); libname = NULL; } while (NULL != head) { - w = head; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin did not remove address `%s'\n", w->addrstring); - GNUNET_CONTAINER_DLL_remove (head, tail, w); - c ++; - GNUNET_free (w->addr); - GNUNET_free (w->addrstring); - GNUNET_free (w); + w = head; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", + w->addrstring); + GNUNET_CONTAINER_DLL_remove(head, tail, w); + c++; + GNUNET_HELLO_address_free(w->address); + GNUNET_free(w->addrstring); + GNUNET_free(w); } if (c > 0) { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin did not remove %u addresses\n", c); + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", + c); } if (NULL != stats) @@ -251,51 +246,44 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 1; } - static void wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { timeout_wait = GNUNET_SCHEDULER_NO_TASK; if (0 == addresses_reported) - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Plugin did not report any addresses, could not check address conversion functions\n"); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + "Plugin did not report any addresses, could not check address conversion functions\n"); end (); } - static void end_badly_now () { if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) { - GNUNET_SCHEDULER_cancel (timeout_wait); - timeout_wait = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; } if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) { - GNUNET_SCHEDULER_cancel (timeout_endbadly); - timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (timeout_endbadly); + timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; } - timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL); + timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); } - static struct GNUNET_TIME_Relative env_receive (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - struct Session * session, - const char *sender_address, - uint16_t sender_address_len) + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_MessageHeader *message) { /* do nothing */ - return GNUNET_TIME_relative_get_zero_(); + return GNUNET_TIME_relative_get_zero_ (); } - static int got_reply; - /** * Take the given address and append it to the set of results sent back to * the client. @@ -309,28 +297,23 @@ address_pretty_printer_cb (void *cls, const char *buf) if (NULL != buf) { got_reply = GNUNET_YES; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Pretty address : `%s'\n", buf); - pretty_printers_running --; + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", buf); + pretty_printers_running--; } else { - if (GNUNET_NO == got_reply) - { - pretty_printers_running --; - GNUNET_break (0); - end_badly_now (); - } + if (GNUNET_NO == got_reply) + { + pretty_printers_running--; + GNUNET_break(0); + end_badly_now (); + } } } - static void -env_notify_address (void *cls, - int add_remove, - const void *addr, - size_t addrlen, - const char *plugin) +env_notify_address (void *cls, int add_remove, + const struct GNUNET_HELLO_Address *address) { struct AddressWrapper *w; struct AddressWrapper *wtmp; @@ -339,150 +322,145 @@ env_notify_address (void *cls, if (GNUNET_YES == add_remove) { - addresses_reported ++; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Adding address of length %u\n", addrlen); + addresses_reported++; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding address of length %u\n", + address->address_length); - for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) + for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) + { + if ((address->address_length == wtmp->address->address_length) && + (0 == memcmp (address->address, wtmp->address->address, address->address_length))) { - if ((addrlen == wtmp->addrlen) && (0 == memcmp (addr, wtmp->addr, addrlen))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Duplicate address notification .... \n"); - return; - } - } - - w = GNUNET_new (struct AddressWrapper); - w->addr = GNUNET_malloc (addrlen); - w->addrlen = addrlen; - memcpy (w->addr, addr, addrlen); - GNUNET_CONTAINER_DLL_insert(head, tail, w); - got_reply = GNUNET_NO; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Testing: address_to_string \n"); - w->addrstring = strdup (api->address_to_string (api, w->addr, w->addrlen)); - if (NULL == w->addrstring) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin cannot convert address to string!\n"); - end_badly_now(); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Plugin added address `%s'\n", w->addrstring); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Testing address_to_string: OK\n"); - } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Testing: string_to_address \n"); - s2a = NULL; - s2a_len = 0; - if ((GNUNET_OK != api->string_to_address (api, w->addrstring, strlen (w->addrstring)+1, &s2a, &s2a_len)) || (NULL == s2a)) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin cannot convert string to address!\n"); - end_badly_now(); - return; - } - - /* - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); - - int c1; - for (c1 = 0; c1 < s2a_len; c1++ ) - fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); - */ - if (s2a_len != w->addrlen) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin creates different address length when converting address->string->address: %u != %u\n", w->addrlen, s2a_len); - } - else if (0 != memcmp (s2a, w->addr, s2a_len)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin creates different address length when converting back and forth %i!\n", memcmp (s2a, w->addr, s2a_len)); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Testing string_to_address: OK\n"); - } - GNUNET_free (s2a); - - pretty_printers_running ++; - api->address_pretty_printer (api->cls, plugin, addr, addrlen, - GNUNET_YES, GNUNET_TIME_UNIT_MINUTES, - &address_pretty_printer_cb, - w); - - if (GNUNET_OK != api->check_address (api->cls, w->addr, w->addrlen)) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin refuses added address!\n"); - end_badly_now(); - return; - } - if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) - { - GNUNET_SCHEDULER_cancel (timeout_wait); - timeout_wait = GNUNET_SCHEDULER_NO_TASK; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Duplicate address notification .... \n"); + return; } + } + + w = GNUNET_new (struct AddressWrapper); + w->address = GNUNET_HELLO_address_copy (address); + GNUNET_CONTAINER_DLL_insert(head, tail, w); + got_reply = GNUNET_NO; + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: address_to_string \n"); + w->addrstring = strdup ( + api->address_to_string (api, w->address->address, + w->address->address_length)); + if (NULL == w->addrstring) + { + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Plugin cannot convert address to string!\n"); + end_badly_now (); + return; + } + else + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Plugin added address `%s'\n", + w->addrstring); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing address_to_string: OK\n"); + } + + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: string_to_address \n"); + s2a = NULL; + s2a_len = 0; + if ((GNUNET_OK + != api->string_to_address (api, w->addrstring, + strlen (w->addrstring) + 1, &s2a, &s2a_len)) || (NULL == s2a)) + { + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Plugin cannot convert string to address!\n"); + end_badly_now (); + return; + } + + /* + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); + + int c1; + for (c1 = 0; c1 < s2a_len; c1++ ) + fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); + */ + if (s2a_len != w->address->address_length) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Plugin creates different address length when converting address->string->address: %u != %u\n", + w->address->address_length, s2a_len); + } + else if (0 != memcmp (s2a, w->address->address, s2a_len)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Plugin creates different address length when converting back and forth %i!\n", + memcmp (s2a, w->address->address, s2a_len)); + } + else + { + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing string_to_address: OK\n"); + } + GNUNET_free(s2a); + + pretty_printers_running++; + api->address_pretty_printer (api->cls, address->transport_name, address->address, address->address_length, GNUNET_YES, + GNUNET_TIME_UNIT_MINUTES, &address_pretty_printer_cb, w); + + if (GNUNET_OK != api->check_address (api->cls, w->address->address, w->address->address_length)) + { + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n"); + end_badly_now (); + return; + } + if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) + { + GNUNET_SCHEDULER_cancel (timeout_wait); + timeout_wait = GNUNET_SCHEDULER_NO_TASK; + } - timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); } else if (GNUNET_NO == add_remove) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing address of length %u\n", addrlen); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing address of length %u\n", + address->address_length); - w = head; - while (NULL != w) + w = head; + while (NULL != w) + { + if ((address->address_length == w->address->address_length) && + (0 == memcmp (w->address->address, address->address, address->address_length))) { - if ((addrlen == w->addrlen) && (0 == memcmp (w->addr, addr, addrlen))) - { - break; - } - w = w->next; - } - - if (w == NULL) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Plugin removes address never added!\n"); - end_badly_now(); - return; + break; } + w = w->next; + } + + if (w == NULL ) + { + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Plugin removes address never added!\n"); + end_badly_now (); + return; + } - GNUNET_CONTAINER_DLL_remove (head, tail, w); - GNUNET_free (w->addr); - GNUNET_free (w->addrstring); - GNUNET_free (w); + GNUNET_CONTAINER_DLL_remove(head, tail, w); + GNUNET_HELLO_address_free (w->address); + GNUNET_free(w->addrstring); + GNUNET_free(w); } else { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Invalid operation: %u\n", add_remove); - end_badly_now (); - return; + GNUNET_break(0); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid operation: %u\n", add_remove); + end_badly_now (); + return; } } - static struct GNUNET_ATS_Information -env_get_address_type (void *cls, - const struct sockaddr *addr, - size_t addrlen) +env_get_address_type (void *cls, const struct sockaddr *addr, size_t addrlen) { struct GNUNET_ATS_Information ats; ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); @@ -490,34 +468,27 @@ env_get_address_type (void *cls, return ats; } - static const struct GNUNET_MessageHeader * env_get_our_hello () { return (const struct GNUNET_MessageHeader *) hello; } - static void -env_session_end (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct Session * session) +env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, + struct Session * session) { } - static void env_update_metrics (void *cls, - const struct GNUNET_PeerIdentity *peer, - const void *address, - uint16_t address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count) { } - static void setup_plugin_environment () { @@ -534,15 +505,13 @@ setup_plugin_environment () env.session_end = &env_session_end; } - static int handle_helper_message (void *cls, void *client, - const struct GNUNET_MessageHeader *hdr) + const struct GNUNET_MessageHeader *hdr) { return GNUNET_OK; } - /** * Runs the test. * @@ -550,10 +519,10 @@ handle_helper_message (void *cls, void *client, * @param c configuration to use */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, char * const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { - char *const *argv = cls; + char * const *argv = cls; unsigned long long tneigh; char *keyfile; char *plugin; @@ -563,66 +532,62 @@ run (void *cls, char *const *args, const char *cfgfile, cfg = c; /* parse configuration */ - if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, - "TRANSPORT", - "NEIGHBOUR_LIMIT", - &tneigh)) || - (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, - "PEER", "PRIVATE_KEY", - &keyfile))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Transport service is lacking key configuration settings. Exiting.\n"); + if ((GNUNET_OK + != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", + "NEIGHBOUR_LIMIT", &tneigh)) + || (GNUNET_OK + != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", + &keyfile))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Transport service is lacking key configuration settings. Exiting.\n"); return; } if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not create statistics. Exiting.\n"); - GNUNET_free (keyfile); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not create statistics. Exiting.\n"); + GNUNET_free(keyfile); end_badly_now (); return; } if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Hostkey `%s' missing. Exiting.\n", - HOSTKEY_FILE); - GNUNET_free (keyfile); - end_badly_now (); - return; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n", + HOSTKEY_FILE); + GNUNET_free(keyfile); + end_badly_now (); + return; } if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not create a directory for hostkey `%s'. Exiting.\n", - keyfile); - GNUNET_free (keyfile); - end_badly_now (); - return; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile); + GNUNET_free(keyfile); + end_badly_now (); + return; } - if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) + if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", - HOSTKEY_FILE, keyfile); - GNUNET_free (keyfile); - end_badly_now (); - return; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", + HOSTKEY_FILE, keyfile); + GNUNET_free(keyfile); + end_badly_now (); + return; } - max_connect_per_transport = (uint32_t) tneigh; my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); - GNUNET_free (keyfile); + GNUNET_free(keyfile); if (NULL == my_private_key) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not access hostkey. Exiting.\n"); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Could not access hostkey. Exiting.\n"); end_badly_now (); return; } @@ -633,18 +598,18 @@ run (void *cls, char *const *args, const char *cfgfile, /* load plugins... */ setup_plugin_environment (); - GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_")); - plugin = strstr(argv[0],"test_plugin_"); - sep = strrchr(argv[0],'.'); + GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_")); + plugin = strstr (argv[0], "test_plugin_"); + sep = strrchr (argv[0], '.'); if (NULL == plugin) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); - end_badly_now (); - return; + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); + end_badly_now (); + return; } plugin += strlen ("test_plugin_"); if (NULL != sep) - sep[0] = '\0'; + sep[0] = '\0'; /* Hack for WLAN: start a second helper */ if (0 == strcmp (plugin, "wlan")) @@ -654,77 +619,73 @@ run (void *cls, char *const *args, const char *cfgfile, helper_argv[1] = (char *) "2"; helper_argv[2] = NULL; suid_helper = GNUNET_HELPER_start (GNUNET_NO, - "gnunet-helper-transport-wlan-dummy", - helper_argv, - &handle_helper_message, - NULL, - NULL); + "gnunet-helper-transport-wlan-dummy", helper_argv, + &handle_helper_message, NULL, NULL ); } /* Loading plugin */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); api = GNUNET_PLUGIN_load (libname, &env); - if (api == NULL) + if (api == NULL ) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to load transport plugin for %s\n", plugin); + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + "Failed to load transport plugin for %s\n", plugin); end_badly_now (); return; } - timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); + timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); /* Check if all functions are implemented */ if (NULL == api->address_pretty_printer) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } if (NULL == api->address_to_string) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } - GNUNET_assert (NULL != api->check_address); + GNUNET_assert(NULL != api->check_address); if (NULL == api->check_address) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } - GNUNET_assert (NULL != api->disconnect_peer); + GNUNET_assert(NULL != api->disconnect_peer); if (NULL == api->disconnect_peer) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } - GNUNET_assert (NULL != api->get_session); + GNUNET_assert(NULL != api->get_session); if (NULL == api->get_session) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } if (NULL == api->address_pretty_printer) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } if (NULL == api->string_to_address) { - GNUNET_break (0); - end_badly_now (); - return; + GNUNET_break(0); + end_badly_now (); + return; } } - /** * The main function for the test * @@ -733,32 +694,22 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main (int argc, char * const *argv) { static struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_END - }; + GNUNET_GETOPT_OPTION_END }; int ret; GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); - char *const argv_prog[] = { - "test_plugin_transport", - "-c", - "test_plugin_transport_data.conf", - NULL - }; - GNUNET_log_setup ("test-plugin-transport", - "WARNING", - NULL); - ok = 1; /* set to fail */ - ret = (GNUNET_OK == GNUNET_PROGRAM_run (3, - argv_prog, - "test-plugin-transport", - "testcase", - options, - &run, - (void *) argv)) ? ok : 1; + char * const argv_prog[] = { "test_plugin_transport", "-c", + "test_plugin_transport_data.conf", NULL }; + GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL ); + ok = 1; /* set to fail */ + ret = + (GNUNET_OK + == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", + "testcase", options, &run, (void *) argv)) ? ok : 1; GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); return ret; } diff --git a/src/transport/transport.h b/src/transport/transport.h index beea4031e..5a2f04056 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -461,6 +461,11 @@ struct PeerIterateResponseMessage struct GNUNET_TIME_AbsoluteNBO state_timeout; /** + * Local info about the address + */ + uint32_t local_address_info GNUNET_PACKED; + + /** * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element */ uint32_t state GNUNET_PACKED; diff --git a/src/transport/transport_api_monitoring.c b/src/transport/transport_api_monitoring.c index ef7a01040..50517cc6c 100644 --- a/src/transport/transport_api_monitoring.c +++ b/src/transport/transport_api_monitoring.c @@ -311,8 +311,7 @@ reconnect (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) * message with the human-readable address */ static void -peer_response_processor (void *cls, - const struct GNUNET_MessageHeader *msg) +peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) { struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; struct PeerIterateResponseMessage *pir_msg; @@ -432,7 +431,7 @@ peer_response_processor (void *cls, /* notify client */ address = GNUNET_HELLO_address_allocate (&pir_msg->peer, - transport_name, addr, alen); + transport_name, addr, alen, ntohl(pir_msg->local_address_info)); pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, address, ntohl(pir_msg->state), GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); |