From ee266d0bd0b96c67ac1c7f76fff41980bb181e64 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jan 2015 21:07:24 +0000 Subject: -indentation plugin_transport_udp.c --- src/transport/gnunet-service-transport.c | 15 ++++--- src/transport/gnunet-service-transport_ats.c | 34 +++++++++++++--- src/transport/gnunet-service-transport_ats.h | 11 ++++++ .../gnunet-service-transport_neighbours.c | 10 ++--- src/transport/plugin_transport_tcp.c | 46 +++++++++++++--------- src/transport/plugin_transport_udp.c | 33 ++++++++++------ src/transport/plugin_transport_wlan.c | 41 ++++++++++++------- src/transport/test_transport_api_reliability.c | 16 +++++--- 8 files changed, 138 insertions(+), 68 deletions(-) (limited to 'src/transport') diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 5126dad96..b21b0c384 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -732,11 +732,15 @@ plugin_env_session_start (void *cls, session, GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); - if (GNUNET_YES == - GNUNET_HELLO_address_check_option (address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)) + if ( (GNUNET_YES == + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)) || + (GNUNET_NO == + GST_ats_is_known (address, session) ) ) { - /* inbound is always new */ + /* inbound is always new, but outbound MAY already be known, but + for example for UNIX, we have symmetric connections and thus we + may not know the address yet; add if necessary! */ GST_ats_add_address (address, session, ats, @@ -744,7 +748,6 @@ plugin_env_session_start (void *cls, } else { - /* outbound should already be known */ GST_ats_new_session (address, session); GST_ats_update_metrics (address, @@ -923,8 +926,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GST_neighbours_stop (); - GST_validation_stop (); GST_plugins_unload (); + GST_validation_stop (); GST_ats_done (); GNUNET_ATS_scheduling_done (GST_ats); GST_ats = NULL; diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index 4fcf7c9dc..a660f252f 100644 --- a/src/transport/gnunet-service-transport_ats.c +++ b/src/transport/gnunet-service-transport_ats.c @@ -108,6 +108,8 @@ find_ai_cb (void *cls, fc->ret = ai; return GNUNET_NO; } + GNUNET_assert ( (fc->session != ai->session) || + (NULL == ai->session) ); return GNUNET_YES; } @@ -137,6 +139,21 @@ find_ai (const struct GNUNET_HELLO_Address *address, } +/** + * Test if ATS knows about this address. + * + * @param address the address + * @param session the session + * @return #GNUNET_YES if address is known, #GNUNET_NO if not. + */ +int +GST_ats_is_known (const struct GNUNET_HELLO_Address *address, + struct Session *session) +{ + return (NULL != find_ai (address, session)) ? GNUNET_YES : GNUNET_NO; +} + + /** * Notify ATS about the new address including the network this address is * located in. @@ -183,7 +200,7 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, if (NULL == (papi = GST_plugins_find (address->transport_name))) { /* we don't have the plugin for this address */ - GNUNET_break(0); + GNUNET_assert (0); return; } if (NULL != session) @@ -244,7 +261,12 @@ GST_ats_new_session (const struct GNUNET_HELLO_Address *address, ai = find_ai (address, NULL); if (NULL == ai) { - GNUNET_break (NULL != (find_ai (address, session))); + /* We may already be aware of the session, even if some other part + of the code could not tell if it just created a new session or + just got one recycled from the plugin; hence, we may be called + with "new" session even for an "old" session; in that case, + check that this is the case, but just ignore it. */ + GNUNET_assert (NULL != (find_ai (address, session))); return; } GNUNET_break (NULL == ai->session); @@ -330,9 +352,9 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address, and if we get metrics for those, they were never known to ATS which means we end up here (however, in this case, the address must be an outbound address). */ - GNUNET_break (GNUNET_YES != - GNUNET_HELLO_address_check_option (address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND)); + GNUNET_assert (GNUNET_YES != + GNUNET_HELLO_address_check_option (address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND)); return; } @@ -394,7 +416,7 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address) ai = find_ai (address, NULL); if (NULL == ai) { - GNUNET_break (0); + GNUNET_assert (0); return; } GNUNET_assert (GNUNET_YES == diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h index b066ad74f..b203cc323 100644 --- a/src/transport/gnunet-service-transport_ats.h +++ b/src/transport/gnunet-service-transport_ats.h @@ -50,6 +50,17 @@ void GST_ats_done (void); +/** + * Test if ATS knows about this address. + * + * @param address the address + * @param session the session + * @return #GNUNET_YES if address is known, #GNUNET_NO if not. + */ +int +GST_ats_is_known (const struct GNUNET_HELLO_Address *address, + struct Session *session); + /** * Notify ATS about the new address including the network this address is * located in. diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index c7459680f..e13bca139 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -800,11 +800,11 @@ set_alternative_address (struct NeighbourMapEntry *n, */ static void set_primary_address (struct NeighbourMapEntry *n, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - int is_active) + const struct GNUNET_HELLO_Address *address, + struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + int is_active) { struct GNUNET_TRANSPORT_PluginFunctions *papi; diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 01a4eade8..770525f21 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -2261,8 +2261,9 @@ handle_tcp_welcome (void *cls, 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); @@ -2277,10 +2278,14 @@ handle_tcp_welcome (void *cls, return; } - LOG(GNUNET_ERROR_TYPE_DEBUG, "Received %s message from `%4s' %p\n", "WELCOME", + 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) { @@ -2288,8 +2293,9 @@ handle_tcp_welcome (void *cls, { LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for peer `%s'\n", - session, GNUNET_a2s (vaddr, alen)); - GNUNET_free(vaddr); + session, + GNUNET_a2s (vaddr, alen)); + GNUNET_free (vaddr); } } else @@ -2337,23 +2343,27 @@ handle_tcp_welcome (void *cls, session->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); ats.value = htonl (session->ats_address_network_type); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Creating new%s session %p for peer `%s' client %p \n", - GNUNET_HELLO_address_check_option (session->address, - GNUNET_HELLO_ADDRESS_INFO_INBOUND) - ? " inbound" : "", - session, - tcp_plugin_address_to_string(NULL, (void *) session->address->address, - session->address->address_length), - client); - GNUNET_free(vaddr); - GNUNET_SERVER_client_set_user_context(session->client, session); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Creating new%s session %p for peer `%s' client %p \n", + GNUNET_HELLO_address_check_option (session->address, + GNUNET_HELLO_ADDRESS_INFO_INBOUND) + ? " inbound" : "", + session, + tcp_plugin_address_to_string (NULL, + (void *) session->address->address, + session->address->address_length), + client); + 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); /* Notify transport and ATS about new session */ - plugin->env->session_start (NULL, session->address, session, &ats, 1); + plugin->env->session_start (plugin->env->cls, + session->address, + session, + &ats, 1); notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 76c9dfdec..5b882af26 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1327,10 +1327,13 @@ udp_disconnect_session (void *cls, struct UDP_MessageWrapper *next; struct FindReceiveContext frc; - GNUNET_assert(GNUNET_YES != s->in_destroy); - LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' address ended\n", s, + 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), - udp_address_to_string (NULL, s->address->address, s->address->address_length)); + udp_address_to_string (NULL, + s->address->address, + s->address->address_length)); /* stop timeout task */ if (NULL != s->timeout_task) { @@ -1405,10 +1408,10 @@ udp_disconnect_session (void *cls, } } - GNUNET_assert(GNUNET_YES == - GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, - &s->target, - s)); + 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), @@ -2335,7 +2338,8 @@ process_udp_message (struct Plugin *plugin, 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))) + if ( (NULL == (s = udp_plugin_lookup_session (plugin, address))) && + (GNUNET_YES != s->in_destroy) ) { s = udp_plugin_create_session (plugin, address); plugin->env->session_start (NULL, address, s, NULL, 0); @@ -2354,9 +2358,12 @@ process_udp_message (struct Plugin *plugin, 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)) free_session (s); @@ -3614,12 +3621,12 @@ libgnunet_plugin_transport_udp_done (void *cls) return NULL; } stop_broadcast (plugin); - if (plugin->select_task != NULL ) + if (plugin->select_task != NULL) { GNUNET_SCHEDULER_cancel (plugin->select_task); plugin->select_task = NULL; } - if (plugin->select_task_v6 != NULL ) + if (plugin->select_task_v6 != NULL) { GNUNET_SCHEDULER_cancel (plugin->select_task_v6); plugin->select_task_v6 = NULL; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index b0be34346..51e8991b9 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1395,7 +1395,6 @@ process_data (void *cls, struct Plugin *plugin = cls; struct GNUNET_HELLO_Address *address; struct MacAndSession *mas = client; - struct MacAndSession xmas; struct GNUNET_ATS_Information ats; struct FragmentMessage *fm; struct GNUNET_PeerIdentity tmpsource; @@ -1448,6 +1447,17 @@ process_data (void *cls, &mas->endpoint->wlan_addr, sizeof (mas->endpoint->wlan_addr), GNUNET_HELLO_ADDRESS_INFO_INBOUND); + mas->session = lookup_session (mas->endpoint, + &tmpsource); + if (NULL == mas->session) + { + mas->session = create_session (mas->endpoint, + &tmpsource); + plugin->env->session_start (plugin->env->cls, + address, + mas->session, + &ats, 1); + } plugin->env->receive (plugin->env->cls, address, mas->session, @@ -1557,34 +1567,34 @@ process_data (void *cls, GNUNET_NO); break; } - xmas.endpoint = mas->endpoint; - if (NULL == (xmas.session = lookup_session (mas->endpoint, - &wlanheader->sender))) + mas->session = lookup_session (mas->endpoint, + &wlanheader->sender); + if (NULL == mas->session) { - xmas.session = create_session (mas->endpoint, + mas->session = create_session (mas->endpoint, &wlanheader->sender); address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME, &mas->endpoint->wlan_addr, sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); - plugin->env->session_start (NULL, + plugin->env->session_start (plugin->env->cls, address, - xmas.session, + mas->session, NULL, 0); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Notifying transport about peer `%s''s new session %p \n", + "Notifying transport about peer `%s''s new session %p \n", GNUNET_i2s (&wlanheader->sender), - xmas.session); + mas->session); GNUNET_HELLO_address_free (address); } LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing %u bytes of DATA from peer `%s'\n", (unsigned int) msize, GNUNET_i2s (&wlanheader->sender)); - xmas.session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); + mas->session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer, - &xmas, + mas, (const char *) &wlanheader[1], msize - sizeof (struct WlanHeader), GNUNET_YES, @@ -2188,9 +2198,12 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) GNUNET_BANDWIDTH_value_init (100 * 1024 * 1024 / 8), 100); - plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); - plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); - plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin); + plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, + plugin); + plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, + plugin); + plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, + plugin); plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon, plugin); diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index a727d3e6a..903e6efdc 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -87,22 +87,22 @@ static int ok; /** * Context of peer 1 */ -struct PeerContext *p1; +static struct PeerContext *p1; /** * Configuration file of peer 1 */ -char *cfg_file_p1; +static char *cfg_file_p1; /** * Context of peer 2 */ -struct PeerContext *p2; +static struct PeerContext *p2; /** * Configuration file of peer 1 */ -char *cfg_file_p2; +static char *cfg_file_p2; /** * Timeout task @@ -112,12 +112,12 @@ static struct GNUNET_SCHEDULER_Task * die_task; /** * Transport transmit handle used */ -struct GNUNET_TRANSPORT_TransmitHandle *th; +static struct GNUNET_TRANSPORT_TransmitHandle *th; /** * Transport testing handle */ -struct GNUNET_TRANSPORT_TESTING_handle *tth; +static struct GNUNET_TRANSPORT_TESTING_handle *tth; /* * Total amount of bytes sent @@ -145,7 +145,9 @@ static int msg_sent; static int msg_recv; static int test_connected; + static int test_sending; + static int test_send_timeout; @@ -167,9 +169,11 @@ static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; #define OKPP do { ok++; } while (0) #endif + static int get_bit (const char *map, unsigned int bit); + static void end () { -- cgit v1.2.3